有人可以帮我解决这个问题,寻找很多解决方案,但对我没有用

时间:2020-02-17 21:08:48

标签: pytorch

企业家错误 图像的大小为([64,3,224,224]) 我尝试更改批量大小或图像大小,但仍然出现错误

Epoch 1/30
----------
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-160-dbcdb17ea6ee> in <module>()
      1 epochs = 30
      2 net.to(device)
----> 3 net = train_model(net, criterion, optimizer, sched, epochs)

2 frames
<ipython-input-157-d34ea1683b12> in forward(self, x)
     12     x = self.pool(F.relu(self.conv1(x)))
     13     x = self.pool(F.relu(self.conv2(x)))
---> 14     x = x.view(x.size(0), 16 * 38 * 38)
     15     x = F.relu(self.fc1(x))
     16     x = F.relu(self.fc2(x))

RuntimeError: shape '[64, 23104]' is invalid for input of size 2876416

1 个答案:

答案 0 :(得分:1)

这是因为空间和通道尺寸的乘积不等于23104,而是等于2876416。要展平张量,可以尝试使用out = out.view(out.size(0), -1),它应该可以正常工作。