Pytorch 有人能帮我解决这个问题,寻找很多解决方案,但他们没有为我工作吗
中间错误 图像的大小为([64,3,224,224]) 我试图更改批大小或图像大小,但仍然出现错误Pytorch 有人能帮我解决这个问题,寻找很多解决方案,但他们没有为我工作吗,pytorch,Pytorch,中间错误 图像的大小为([64,3,224,224]) 我试图更改批大小或图像大小,但仍然出现错误 Epoch 1/30 ---------- --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-160-dbcd
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/30纪元
----------
---------------------------------------------------------------------------
运行时错误回溯(上次最近调用)
在()
1个时代=30
2净至(设备)
---->3净=列车模型(净、标准、优化器、计划、时代)
2帧
前进中(自我,x)
12 x=self.pool(F.relu(self.conv1(x)))
13 x=自池(F.relu(self.conv2(x)))
--->14 x=x.视图(x.尺寸(0),16*38*38)
15 x=F.relu(自fc1(x))
16 x=F.relu(自fc2(x))
运行时错误:形状“[6423104]”对于大小为2876416的输入无效
这是因为空间和通道尺寸的乘积不等于23104,而是等于2876416。要展平张量,可以尝试使用out=out.view(out.size(0),-1)
,这应该可以正常工作