国家网站备案查询,网站建设属于什么费,网站功能描述,汕头网站开发RuntimeError: size mismatch, m1: [80 x 4], m2: [320 x 50] at …\aten\src\TH/generic/THTensorMath.cpp:41
使用pytorch进行深度学习的训练会出现这种问题#xff0c;原因是fc全连接层的输入维度问题#xff0c;由于输入是二维的数据#xff0c;很多时候在输入全连接层…RuntimeError: size mismatch, m1: [80 x 4], m2: [320 x 50] at …\aten\src\TH/generic/THTensorMath.cpp:41
使用pytorch进行深度学习的训练会出现这种问题原因是fc全连接层的输入维度问题由于输入是二维的数据很多时候在输入全连接层的时候我们没有调整维度 例如
def forward(self, input):x self.pool1(F.relu(self.conv1(input)))x self.pool2(F.relu(self.conv2(x)))x self.fc1(x)x self.fc2(x)return x我们的fc1的输入将是804的情况而需要的是3201的情况这时会报错
改为
def forward(self, input):x self.pool1(F.relu(self.conv1(input)))x self.pool2(F.relu(self.conv2(x))).view(320)x self.fc1(x)x self.fc2(x)return x使用view调整维度即可