nn.linear输入三维张量
时间: 2023-11-11 14:05:02 浏览: 206
pytorch中nn.Conv1d的用法详解
nn.Linear可以接受三维张量作为输入。根据官方文档的解释,nn.Linear的输入和输出的维度可以是任意的,无论是二维、三维还是更高维度的张量都可以。对于一个三维张量\[batch_size, H, d_model\],经过nn.Linear后,输出的形状除了最后一个维度不变,其他维度与输出一样。例如,对于一个形状为\[batch_size, H, d_model\]的张量,通过nn.Linear(d_model, d_ff)的线性层,输出的形状将变为\[batch_size, H, d_ff\]。所以,你可以放心使用nn.Linear处理三维张量的输入。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* [关于torch.nn.Linear的输入与输出探讨](https://blog.csdn.net/qq_36258516/article/details/117333424)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [关于 torch.nn.Linear 的输入维度问题](https://blog.csdn.net/qq_45100200/article/details/121943130)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [nn.Linear() 函数可二维或三维输入](https://blog.csdn.net/m0_61899108/article/details/129926633)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文