Hi I want to use the MoCo model. It is like the Resnet. And I don’t need all of the layers. How to quit some of the layers I don’t want. I find some codes regarding quiting layers after fc6 of Alexnet. But I don’t know how to realize that in MoCo model, something like RESNET50.
#below cnn is the pretrained alexnet. layers_to_use=‘fc6’.
cnn = get_pretrained_net(pretrained_net).type(dtype)
opt_content = {‘layers’: layers_to_use, ‘what’:‘features’}

Remove the layers we don’t need
keys = [x for x in cnn._modules.keys()]
max_idx = max(keys.index(x) for x in opt_content[‘layers’].split(’,’))
for k in keys[max_idx+1:]:
cnn._modules.pop(k)   

print(cnn)