【发布时间】:2019-02-28 00:51:27
【问题描述】:
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'
我从网上得到了这段代码,我下载了 alexnet_places365.pth.tar ,当我运行它时,它显示上述错误
【问题讨论】:
标签: deep-learning computer-vision conv-neural-network pytorch