RuntimeError: mat1 and mat2 shapes cannot be multiplied (128x16 and 28x128)
时间: 2024-01-22 08:36:22 浏览: 116
这个错误通常表示矩阵乘法操作的维度不匹配。根据错误信息,mat1是一个128x16的矩阵,而mat2是一个28x128的矩阵,它们的维度无法相乘。这个错误通常是由于定义网络结构时,全连接层的输入和输出维度不匹配导致的。在你提供的代码中,错误可能出现在定义网络结构的最后一层全连接层。根据引用和引用的内容,你可以检查一下网络结构中最后一层全连接层的输入和输出维度是否匹配。根据这个错误信息,你可以尝试检查一下最后一层全连接层的输入维度是否为128,输出维度是否为4,以确保它们匹配。这样做应该能够解决这个错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [RuntimeError: mat1 and mat2 shapes cannot be multiplied (250x7 and 9x256) pytorch报错](https://blog.csdn.net/qq_44679208/article/details/130751469)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [RuntimeError: mat1 and mat2 shapes cannot be multiplied (5760x6 and 128x4)](https://blog.csdn.net/Learn_signal/article/details/126722129)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文