학습 중간에 parameter를 확인하고 싶을 때가 있다.

class CustomModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(3,1)
        
    def forward(self, x):
        return self.linear(x)
        
        
model = CustomModel()

다음과 같은 간단한 linear form이 있을 때

params = list(model.parameters())

위와 같이 한다면

[Parameter containing:
 tensor([[1.1857, 0.3697, 0.5246]], requires_grad=True),
 Parameter containing:
 tensor([-0.0688], requires_grad=True)]

다음과 같은 결과를 얻을 수 있다.

 

paramters()는 iterator를 반환하기 때문에, list로 처리해주면 그 값을 확인해볼 수 있다.

'머신 러닝 및 파이썬 > 딥러닝 기초 , 파이토치' 카테고리의 다른 글

Tensor Manipulation  (0) 2021.01.03
Multi-layer 예시 [Diabetes Logistics]  (0) 2020.12.29
Linear Regression  (0) 2020.12.29
Supervised Learning  (0) 2020.02.18

+ Recent posts