728x90
Pytorch Code를 보다보면 다음과 같이 Variable로 Tensor를 감싸는 경우를 볼 수 있다.
for input, _ in tr:
input = Variable(input.cuda(async=True))
이는 해당 Tensor의 gradient의 변화를 추적하고 싶을 때 사용하는 것이다.
위와 같이 하고 'required_grad=True' 옵션을 주면 gradient 변화량을 확인할 수 있다.
이때 명령어를 다음과 같이 하면 된다.
print(input.grad)
그러나 현재는 모든 tensor에서 required_grad 옵션을 통해 gradient를 추적할 수 있기 때문에
따로 위와 같이 Variable로 감싸줄 필요가 없다.
(현재는 쓸 필요 없음)
https://aigong.tistory.com/179
torch.autograd.Variable 알아보기
torch.autograd.Variable 알아보기 목차 PyTorch Autograd Variable 한글 튜토리얼 9bow.github.io/PyTorch-tutorials-kr-0.3.1/beginner/blitz/autograd_tutorial.html Autograd: 자동 미분 — PyTorch Tutorial..
aigong.tistory.com
728x90
'Pytorch' 카테고리의 다른 글
Pytorch : Dataloader num_workers (0) | 2021.06.01 |
---|---|
Deep learning model code basic structure (0) | 2021.04.28 |
THOP: PyTorch-OpCounter (0) | 2021.04.01 |
visualization (0) | 2020.08.05 |
torch.utils.data.DataLoader (0) | 2020.06.20 |