티스토리 뷰
1 .data
.data
가 헷갈려 쓰는 포스팅
.data
was the primary way to get the underlying Tensor from a Variable. After this merge, calling y = x.data still has similar semantics. So y will be a Tensor that shares the same data with x, is unrelated with the computation history of x, and has requires_grad=False.
However,
.data
can be unsafe in some cases. Any changes on x.data wouldn't be tracked by autograd, and the computed gradients would be incorrect if x is needed in a backward pass. A safer alternative is to use x.detach(), which also returns a Tensor that shares data with requires_grad=False, but will have its in-place changes reported by autograd if x is needed in backward.
정리하자면
.data
는 tensor 데이터는 공유 하되 required_grad 는 False로 설정된다. 중요한 건 데이터를 공유하기 때문에 .data로 할당된 어떤 tensor를 바꾼다면 원래 tensor도 바뀐다.
밑에 있는 케이스는 어떤 상황인지 아직 잘 모르겠다. pass
2 .item
size가 1 인 torch tensor를 python scalar로 변환
'컴퓨터 과학 이야기(Computer Science) > PyTorch' 카테고리의 다른 글
Pytorch Variable (0) | 2019.02.27 |
---|
- Total
- Today
- Yesterday
- 비트 벡터
- variable
- 비쥬얼스튜디오코드
- Pytorch Variable
- Visual Studio Code에서 R
- vscode
- 파이토치
- scikit learn
- 사이킷런
- pytorch
- sklearn.model_selection.KFold
- 교차검증
- vs code
- 박사과정 #PhD
- 사이킷런 KFold
- r
- sublime text
- Pytorch .data
- cross validation
- Bit vector
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |