我是靠谱客的博主 顺心网络,这篇文章主要介绍RuntimeError: mat1 dim 1 must match mat2 dim 0 报错解决,现在分享给大家,希望可以做个参考。

原因是输入特征的维度不匹配导致

解决方案1:使用avg_pool2d函数将特征图转换成1维

复制代码
1
2
3
4
5
6
7
8
self.linear3 = nn.Linear(96, 128) ''' ''' #如果输入的每个特征图的大小是10x2,则用kernel_size=10x2, 对每个10x2的特征图进行avg_pool out = F.avg_pool2d(out, (10,2)) out = out.view(out.size(0), -1) out = self.linear3(out)

解决方案2:使用AdaptiveAvgPool2d自适应平均池化,不用额外计算特征图大小

复制代码
1
2
3
4
5
6
7
8
self.linear3 = nn.Linear(96, 128) self.avg = nn.AdaptiveAvgPool2d(1)#自适应平均池化 ''' ''' out = self.avg(out) out = out.view(out.size(0), -1) out = self.linear3(out)

最后

以上就是顺心网络最近收集整理的关于RuntimeError: mat1 dim 1 must match mat2 dim 0 报错解决的全部内容,更多相关RuntimeError:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部