0
votes
    import torch
    import torch.nn as nn
    from torch.autograd import Variable
    import torchvision.models as models

    class AlexSal(nn.Module):
        def __init__(self):
            super(AlexSal, self).__init__()
            self.features = nn.Sequential(*list(torch.load('alexnet_places365.pth.tar').features.children())[:-2])
            self.relu = nn.ReLU()
            self.sigmoid = nn.Sigmoid()
            self.conv6 = nn.Conv2d(256, 1, kernel_size=(1, 1), stride=(1, 1))

        def forward(self, x):
            x = self.relu(self.features(x))
            x = self.sigmoid(self.conv6(x))
            x = x.squeeze(1)
            return x
    model = AlexSal().cuda()

Traceback (most recent call last):
  File "main.py", line 23, in <module>
    model = AlexSal().cuda()
  File "main.py", line 13, in __init__
    self.features = nn.Sequential(*list(torch.load('alexnet_places365.pth.tar').features.children())[:-2])
AttributeError: 'dict' object has no attribute 'features'

I got this piece of code from internet , i downloaded alexnet_places365.pth.tar ,and when i am running this , it is showing the above error

1

1 Answers

0
votes

It looks like torch.load('alexnet_places365.pth.tar') does not contain an object with a member features, but instead a state dict as described here.

I would suggest you print out the result of torch.load('alexnet_places365.pth.tar') and then look for an entry features.