AttributeError: 'OrderedDict' object has no attribute 'parameters'


Hi, I am new to Pytorch and I am trying to extract features from pretrained models and dump into pickle, but ran into an Error.

vgg = models.vgg16_bn(pretrained=True)
model = nn.Sequential(*(vgg.features[i] for i in xrange(29))), 'model.pth')
def extract_features(root, files, transform, batch_size, shuffle, num_workers, model):

    dataloader = get_loader(root, files, transform, batch_size, shuffle, num_workers)
    model = model.cuda()

    features = []
    imnames = []
    n_iters = len(dataloader)
    for i, (images, names) in enumerate(dataloader):
        images = Variable(images).cuda()
        feas = model(images).cpu() # The error comes after this line

        if (i+1)%100 == 0:
            print 'iter [%d/%d] finsihed.'%(i, n_iters)

    return, 0), imnames

File “./utils/”, line 38, in extract_features
feas = model(images).cpu()
File “$HOME/.local/lib/python2.7/site-packages/torch/nn/modules/”, line 357, in call
result = self.forward(*input, **kwargs)
File “$HOME/.local/lib/python2.7/site-packages/torch/nn/parallel/”, line 72, in forward
replicas = self.replicate(self.module, self.device_ids[:len(inputs)])
File “$HOME/.local/lib/python2.7/site-packages/torch/nn/parallel/”, line 77, in replicate
return replicate(module, device_ids)
File “$HOME/.local/lib/python2.7/site-packages/torch/nn/parallel/”, line 10, in replicate
params = list(network.parameters())
AttributeError: ‘OrderedDict’ object has no attribute ‘parameters’

Could you please light up the problem? Many thanks!