我正在尝试将 Resnet50 用于图像分类问题。但是它显示错误,我无法修复它。
RuntimeError: inconsistent tensor size, expected tensor [120 x 2048] and src [1000 x 2048] to have the same number of elements, but got 245760 and 2048000 elements respectively at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensorCopy.c:86
并且错误发生在下面。
self.resnet = models.resnet50(num_classes=num_breeds, pretrained='imagenet')
型号如下
class Resnet(nn.Module):
def __init__(self):
super(Resnet,self).__init__()
self.resnet = models.resnet50(num_classes=num_breeds, pretrained='imagenet')
#self.resnet = nn.Sequential(*list(resnet.children())[:-2])
#self.fc = nn.Linear(2048,num_breeds)
def forward(self,x):
x = self.resnet(x)
return x