ptrblck:

Could you give a working code snipped throwing your error?


Sorry, I omitted to post my modification to the vggnet16.
The error is fixed by the following way .
model = torchvision.models.vgg16_bn(pretrained=True)
model.classifier = nn.Sequential(*(model.classifier[i] for i in
                                range(4)))

However, if I modify the pretrained VGGNET model in the following way, the error will occur.
 model = torchvision.models.vgg16_bn(pretrained=True)
 model_finetune = list(model.features)
 model_finetune.extend((list(model.classifier)[:4]))
 model_finetune = nn.Sequential(*model_finetune)