Skip to content

Commit

Permalink
add url to pretrained checkpoints to README.md, small corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasverelst committed Jun 18, 2020
1 parent 63e086e commit a29b33f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
14 changes: 13 additions & 1 deletion classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ The other requirements (matplotlib, tqdm, numpy...) can be installed using pip:

pip install -r requirements.txt

### Evaluate a pretrained sparse DynConv network
### Trained models
Our trained models can be found here: [Microsoft OneDrive link](https://1drv.ms/u/s!ApImBF1PK3gnjoocGrSm908HR9-xuw?e=BWkRZF)

Unzip and place them into the root of the classification folder, so the folder structure looks as follows:
> ./main_cifar.py
> ./main_imagenet.py
> ./exp/cifar/resnet32/...
> ./exp/cifar/resnet26/...
> ./exp/imagenet/...
> ...

### Evaluate a trained sparse DynConv network

python main_cifar.py --model resnet32 -r exp/cifar/resnet32/sparse07/checkpoint_best.pth --budget 0.7 -e

Expand Down
2 changes: 1 addition & 1 deletion classification/main_cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def validate(args, val_loader, model, criterion, epoch):
plt.show()

print(f'* Epoch {epoch} - Prec@1 {top1.avg:.3f}')
print(f'* FLOPS (multiply-accumulates, MACs) per image: {model.compute_average_flops_cost()[0]/1e6:.6f} MMac')
print(f'* average FLOPS (multiply-accumulates, MACs) per image: {model.compute_average_flops_cost()[0]/1e6:.6f} MMac')
model.stop_flops_count()
return top1.avg

Expand Down
2 changes: 1 addition & 1 deletion classification/main_imagenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def validate(args, val_loader, model, criterion, epoch):
viz.showKey()

print(f'* Epoch {epoch} - Prec@1 {top1.avg:.3f}')
print(f'* FLOPS (multiply-accumulates, MACs) per image: {model.compute_average_flops_cost()[0]/1e6:.6f} MMac')
print(f'* average FLOPS (multiply-accumulates, MACs) per image: {model.compute_average_flops_cost()[0]/1e6:.6f} MMac')
model.stop_flops_count()
return top1.avg

Expand Down
8 changes: 7 additions & 1 deletion classification/models/resnet_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ class BasicBlock(nn.Module):
"""Standard residual block """
expansion = 1

def __init__(self, inplanes, planes, stride=1, downsample=None, sparse=False):
def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1,
base_width=64, dilation=1, norm_layer=None, sparse=False):
super(BasicBlock, self).__init__()
assert groups == 1
assert dilation == 1
if norm_layer is None:
norm_layer = nn.BatchNorm2d

self.conv1 = conv3x3(inplanes, planes, stride)
self.bn1 = nn.BatchNorm2d(planes)
self.relu = nn.ReLU(inplace=True)
Expand Down
8 changes: 4 additions & 4 deletions pose/lib/core/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def validate(config, val_loader, val_dataset, model, criterion, output_dir,

avg_flops, total_flops, batch_count = model.compute_average_flops_cost()
logger.info(f'# PARAMS: {get_model_parameters_number(model, as_string=False)/1e6} M')
logger.info(f'# FLOPS (multiply-accumulates, MACs): {(total_flops/idx)/1e9} GMacs on {idx} images')
logger.info(f'# average FLOPS (multiply-accumulates, MACs) per image: {(total_flops/idx)/1e9} GMacs on {idx} images')

# some conditional execution statistics
if len(flops_per_layer) > 0:
Expand All @@ -342,17 +342,17 @@ def validate(config, val_loader, val_dataset, model, criterion, output_dir,
s = ''
for perc in perc_per_layer_avg:
s += f'{round(float(perc), 2)}, '
logger.info(f'# FLOPS (multiply-accumulates MACs) used percentage per layer (average): {s}')
logger.info(f'# average FLOPS (multiply-accumulates MACs) used percentage per layer (average): {s}')

s = ''
for std in perc_per_layer_std:
s += f'{round(float(std), 2)}, '
logger.info(f'# FLOPS (multiply-accumulates MACs) used percentage per layer (standard deviation): {s}')
logger.info(f'# average FLOPS (multiply-accumulates MACs) used percentage per layer (standard deviation): {s}')


exec_cond_flops = int(torch.sum(flops_per_layer))/idx
total_cond_flops = int(torch.sum(total_per_layer))/idx
logger.info(f'# Conditional FLOPS (multiply-accumulates MACs) over all layers (average per image): {exec_cond_flops/1e9} GMac out of {total_cond_flops/1e9} GMac ({round(100*exec_cond_flops/total_cond_flops,1)}%)')
logger.info(f'# Conditional average FLOPS (multiply-accumulates MACs) over all layers (average per image): {exec_cond_flops/1e9} GMac out of {total_cond_flops/1e9} GMac ({round(100*exec_cond_flops/total_cond_flops,1)}%)')

return perf_indicator

Expand Down

0 comments on commit a29b33f

Please sign in to comment.