how to know the parameters of networks in pytorch

if you want to see the parameters of the networks you can know that
the parameters of network is a generator instance.


class Net(nn.Module):
    def __init__(self):
        super(Net,self).__init__()
        self.l1=nn.Linear(1,4)
#         self.relu=nn.ReLU()
        self.l2=nn.Linear(4,2)
    


    def forward(self,x):
        x=self.l1(x)
        x=self.relu(x)
        x=self.l2(x)
        return x

the architecture is above
if you execute this command

net=Net()
print(net.parameters())
for i in net.parameters():
	print(i)
#<generator object Module.parameters at 0x7f8df0c6af68>

the result is like this

Parameter containing:
tensor([[ 0.2810],
        [ 0.7666],
        [ 0.7390],
        [-0.8258]], requires_grad=True)
1
Parameter containing:
tensor([ 0.2996,  0.0812, -0.7105, -0.7501], requires_grad=True)
2
Parameter containing:
tensor([[-0.2219,  0.2144,  0.2282,  0.4191],
        [ 0.0240, -0.0262, -0.4772,  0.2216]], requires_grad=True)
3
Parameter containing:
tensor([0.4966, 0.4801], requires_grad=True)
4

the first tensor is the first layer which is 41
the second tensor is the bias of the the first layer so it’s also 4
1
the second tensor is the second layer which is 42
the second layer is the bias of the second layer which is 1
2

to be continued

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值