self.weight = nn.Parameter(torch.FloatTensor(out_features, in_features)) 和self.weight = nn.Linear(in_features, out_features) 有什么区别?
- 初始化方式不一样,nn.Parameter初始化方式需要指定,nn.Linear默认是Kaiming初始化
- nn.Linear默认有个bias
nn.ModuleList和nn.Sequential区别
nn.ModuleList不会自动连接子模块,需要在forward方法中显式地调用每个模块的前向传播。但是nn.Sequential是一种便捷的方式,用于定义按顺序执行的神经网络层
nn.ModuleList示例
import torch
import torch.nn as nn
class MyModel(nn.Module):
def __init__(self):
super(MyModel, self).__init__()

最低0.47元/天 解锁文章
1968

被折叠的 条评论
为什么被折叠?



