You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! Faced with the problem of increasing the amount of CPU and gpu RAM, which is required to pass the test by a convolutional neural network. The code is given below. This may probably be due to attempts to restore the thinned scales. I will be glad to hear exactly the explanation)!!!
importtorch_pruningastpifisinstance(model, nn.DataParallel):
model=model.moduleprint("DataParallel wrapper removed.")
# Freeze all layersforparaminmodel.parameters():
param.requires_grad=Trueexample_inputs=torch.randn(1, 3, 224, 224)
# Move example_inputs to the same device as the modelexample_inputs=example_inputs.to('cpu') # Move to GPUimportance=tp.importance.GroupNormImportance(p=2)
# model = model.modulemodel=model.to('cpu')
# ignore final layerignored_layers= []
forname, moduleinmodel.named_modules():
ifname=='fc':
ignored_layers.append(module)
# ignore first layerforname, moduleinmodel.named_modules():
ifname=='conv1':
ignored_layers.append(module)
print(ignored_layers)
pruner=tp.pruner.MetaPruner( # We can always choose MetaPruner if sparse training is not required.model,
example_inputs,
importance=imp,
pruning_ratio=0.5, # remove 50% channels, ResNet18 = {64, 128, 256, 512} => ResNet18_Half = {32, 64, 128, 256}# pruning_ratio_dict = {model.conv1: 0.2, model.layer2: 0.8}, # customized pruning ratios for layers or blocksignored_layers=ignored_layers,
)
And in my case:
Average cpu memory with ResNet-50 for test: 1289.12
Average cpu memory with PRUNED (50%+fine-tuning+50%) ResNet-50 for test: 1536.86 MB
The text was updated successfully, but these errors were encountered:
Hello! Faced with the problem of increasing the amount of CPU and gpu RAM, which is required to pass the test by a convolutional neural network. The code is given below. This may probably be due to attempts to restore the thinned scales. I will be glad to hear exactly the explanation)!!!
Test function for CPU (Similar for gpu use):
Pruning:
And in my case:
Average cpu memory with ResNet-50 for test: 1289.12
Average cpu memory with PRUNED (50%+fine-tuning+50%) ResNet-50 for test: 1536.86 MB
The text was updated successfully, but these errors were encountered: