1、Motivation:
I wanna modify the value of some param;
I wanna check the value of some param.
The needed function:
2、state_dict() #generator type
model.modules()#generator type
named_parameters()#OrderDict type
from torch import nn
import torch
#creat a simple model
model = nn.Sequential(
nn.Conv3d(1,16,kernel_size=1),
nn.Conv3d(16,2,kernel_size=1))#tend to print the W of this layer
input = torch.randn([1,1,16,256,256])
if torch.cuda.is_available():
print('cuda is avaliable')
model.cuda()
input = input.cuda()
#打印某一层的参数名
for name in model.state_dict():
print(name)
#Then I konw that the name of target layer is '1.weight'
#schemem1(recommended)
print(model.state_dict()['1.weight'])
#scheme2