mat1 and mat2 shapes cannot be multiplied ( )的解决
问题描述
错误代码:
class Net(nn.Module):def __init__(self):super(Net, self).__init__()# nn.Conv2d(input_channel, output_channel, kernel, stride)self.conv1 = nn.Conv2d(3,64,5,1,1) # 64个5*5的filter -> 64个124*124的matrixself.conv2 = nn.Conv2d(64,128,5,1,1)self.conv3 = nn.Conv2d(128,256,5,1,1)self.conv4 = nn.Conv2d(256,256,5,1,1)self.conv4_drop = nn.Dropout2d()self.fc1 = nn.Linear(4*4*256, 3072) # 全连接层 4*4*256=4096self.fc2 = nn.Linear(3072, 2048)self.fc3 = nn.Linear(2048, 1024)self.fc4 = nn.Linear(1024, 256)self.fc5 = nn.Linear(256, 11)def forward(self, x):# maxpooling 1x = self.conv1(x)x = F.relu(x) # 124*124*64x = F.max_pool2d(x, 2) # 62*62*20# maxpooling 2x = self.conv2(x)x = F.relu(x) # 58*58*128x = F.max_pool2d(x, 2) # 29*29*40# maxpooling 3x = self.conv3(x)x = F.relu(x) # 25*25*256x = F.max_pool2d(x, 2) # 12*12*100# maxpooling 4x = self.conv4(x)x = F.relu(x) # 8*8*256x = F.max_pool2d(x, 2) # 4*4*256# view函数将张量x变形成一维向量形式,总特征数不变,为全连接层做准备x = x.view(-1,4*4*256)x = F.relu(self.fc1(x))x = F.relu(self.fc2(x))x = F.relu(self.fc3(x))x = self.fc4(x)return F.LogSoftmax(x)
错误原因:
x = x.view(x.size()[0], -1)
改为:
x = x.view(-1,4x4x256)
self.fc1 = nn.Linear(4x4x256, 3072)
x.view的第二个参数和nn.Linear第一个参数一致
mat1 and mat2 shapes cannot be multiplied ( )的解决相关推荐
- RuntimeError: mat1 and mat2 shapes cannot be multiplied (1024x1 and 1024x3)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (1024x1 and 1024x3) 前言:在学习pytorch 搭建神经网络的时候, ...
- RuntimeError: mat1 and mat2 shapes cannot be multiplied
RuntimeError: mat1 and mat2 shapes cannot be multiplied RuntimeError: mat1 and mat2 shapes cannot be ...
- 解决:RuntimeError: mat1 and mat2 shapes cannot be multiplied (8x256 and 8x256)维度不匹配问题
在设计网络是,前面几层是去噪网络,后边几层是分类网络,因为之前没有接触过分类任务,对全连接层输入维度不太理解,出现错误RuntimeError: mat1 and mat2 shapes cannot ...
- RuntimeError: mat1 and mat2 shapes cannot be multiplied (32x7 and 784x1024) 报错解决
RuntimeError: mat1 and mat2 shapes cannot be multiplied (32x7 and 784x1024) 运行pytorch时,出现以下报错: 错误代码: ...
- pytorch报错:RuntimeError: mat1 and mat2 shapes cannot be multiplied (64x2500 and 3020x1600)
相信同学们在刚接触深度学习的时候老会遇到类似的问题: 这个其实就是卷积层到全连接层之间的参数数量不对应的问题 卷积层的的输出结果是64*2500的矩阵,那么全连接层的第一个第一层的就应该是:2500* ...
- AI绘画(sd webui)报错mat1 and mat2 shapes cannot be multiplied的处理
问题描述 在用webui转换游戏图标的风格时,使用controlnet固定图标样式,运行报错:RuntimeError: mat1 and mat2 shapes cannot be multipli ...
- RuntimeError: mat1 and mat2 shapes cannot be multiplied (3584x7 and 25088x4096)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (3584x7 and 25088x4096) 使用VGG19提取图像特征时出现该问题 ...
- Pytorch vgg16 实现CIFAR10数据集分类 以及RuntimeError: mat1 and mat2 shapes cannot be multiplied终极详解
最近从tensorflow转战pytorch,今天又遇到了了一个大坑:RuntimeError: mat1 and mat2 shapes cannot be multiplied,网上的结果大都模模 ...
- RuntimeError mat1 and mat2 shapes cannot be multiplied
详细显示如下 x = self.fc(x) File "D:\Python36\lib\site-packages\torch\nn\modules\module.py", lin ...
最新文章
- java开放源码_开放源码的第一周:我是如何参与的,以及我学到的东西
- EXE 文件打不开的处理办法
- SonarQube代码质量管理平台安装与使用--转载
- 转:Google论文之三----MapReduce
- java 流程控制篇 2021/02/26持续更新中
- spring boot controller 增加指定前缀的两种方法
- BugkuCTF-MISC题普通的二维码
- 脚手架 - props
- 转载:JAVA日期处理
- Spring Cloud Alibaba Seata处理分布式事务及案例实战
- [环境搭建]-Web Api搭建到IIS服务器后PUT请求返回HTTP Error 405.0 - Method Not Allowed 解决方法
- Protel 99 SE库文件添加时“file is not recognized”
- iphone屏幕镜像如何全屏_苹果手机投到电视上能全屏嘛
- java word书签_Java 给Word中的指定字符串添加书签
- AD 画PCB 布线时,连线就变绿
- bugzilla perl mysql apache windows,windows下配置bugzilla
- Python基本编程题
- seo优化:如何写伪原创文章
- android 隐藏虚拟键盘,android隐藏全面屏虚拟键盘实现
- 2021世界燕窝展|上海滋补品展谈燕窝可以提高人体的免疫力?