RuntimeError:大小不匹配,m1:[4 x 3136],m2:[64 x 5],位于c:\ a \ w \ 1 \ s \ tmp_conda_3.7_1 [英] RuntimeError: size mismatch, m1: [4 x 3136], m2: [64 x 5] at c:\a\w\1\s\tmp_conda_3.7_1

查看:57
本文介绍了RuntimeError:大小不匹配,m1:[4 x 3136],m2:[64 x 5],位于c:\ a \ w \ 1 \ s \ tmp_conda_3.7_1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用python 3,当我插入变换随机作物尺寸224时,会出现匹配失败的错误.

I used python 3 and when i insert transform random crop size 224 it gives miss match error.

这里是我的代码

我怎么了?

推荐答案

您的代码对 resnet :您更改了渠道数量,每个级别"的瓶颈数量,并完全删除了级别".因此,在 layer3 末尾具有的要素地图的尺寸​​为 64:您的空间尺寸大于 nn.AvgPool2d(8) .您收到的错误消息实际上告诉您 level3 的输出的形状为 64 x 56 x 56 在使用内核进行平均池化并跨度为8后,您有了 64 x 7 x 7 = 3136 维度特征向量您期望的只有64个.

Your code makes variations on resnet: you changed the number of channels, the number of bottlenecks at each "level", and you removed a "level" entirely. As a result, the dimension of the feature map you have at the end of layer3 is not 64: you have a larger spatial dimension than you anticipated by the nn.AvgPool2d(8). The error message you got actually tells you that the output of level3 is of shape 64x56x56 and after avg pooling with kernel and stride 8 you have 64x7x7=3136 dimensional feature vector, instead of only 64 you are expecting.

你能做什么?
与标准" resnet相反,您从 conv1 中删除了跨步,并且在 conv1 之后没有最大池.此外,您删除了也有很大进步的 layer4 .因此,您可以在网络中添加池以减小 layer3 的空间尺寸.
或者,您可以将 nn.AvgPool(8)替换为 nn.AdaptiveAvgPool2d([1,1]) 一个avg池,无论输入要素图的空间尺寸如何,该池只会输出一个要素.

What can you do?
As opposed to "standard" resnet, you removed stride from conv1 and you do not have max pool after conv1. Moreover, you removed layer4 which also have a stride. Therefore, You can add pooling to your net to reduce the spatial dimensions of layer3.
Alternatively, you can replace nn.AvgPool(8) with nn.AdaptiveAvgPool2d([1, 1]) an avg pool that outputs only one feature regardless of the spatial dimensions of the input feature map.

这篇关于RuntimeError:大小不匹配,m1:[4 x 3136],m2:[64 x 5],位于c:\ a \ w \ 1 \ s \ tmp_conda_3.7_1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆