- import torch
- import torch.nn as nn
- # 定义线性层
- linear_layer = nn.Linear(in_features=10, out_features=5, bias=True)
- # 输入数据
- input_data = torch.randn(32, 10) # (batch_size=32, in_features=10)
- # 前向传播
- output = linear_layer(input_data)
- print(output.shape) # 输出形状: (32, 5)
复制代码 维度变革
- 输入:(batch_size, in_features)。
- 输出:(batch_size, out_features)。
示例
- 输入形状:(32, 10)。
- 线性层:nn.Linear(10, 5)。
- 输出形状:(32, 5)。
实现细节:矩阵乘法
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |