Python/Python Error Solution
2022. 5. 21. 16:01
문제 의식
narrow(), expand(), view(), transpose()를 통해 tensor의 모양을 변화시킬 경우 새로운 텐서를 생성하는 것이 아니라 저장된 tensor memory 주소는 그대로 둔채 모양만 바꾼다.
이런 경우 tensor의 메모리를 강제로 연속적으로 만들어줄 필요가 있다. 이를 위한 해결 법은 크게 2가지이다.
해결법 1. torch.Tensor.contiguous 사용하기
본 방법과 관련한 설명은 아래 링크에 정리해두었다. 참조하길 바란다.
만약 바라보지 않고 해결법을 원한다면 다음과 같은 코드를 기입하길 바란다.
# tensor.view(~) 대신 아래 코드 사용
tensor.contiguous().view(~)
https://aigong.tistory.com/430
[Pytorch] torch.Tensor.contiguous 이유와 사용법
[Pytorch] torch.Tensor.contiguous 이유와 사용법 목차 torch.Tensor.contiguous란 https://pytorch.org/docs/stable/generated/torch.Tensor.contiguous.html torch.Tensor.contiguous — PyTorch 1.11.0 doc..
aigong.tistory.com
해결법 2. torch.Tensor.reshape 사용하기
# tensor.view(~) 대신 아래 코드 사용
tensor.reshape(~)
[Colab] ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so)
2022.05.30
[Error 해결법] RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results have already been freed. Specify retain_graph=True when calling b ackward the first time.
2022.05.25
Bad key "text.kerning_factor" on line 4 in ... site-packages/matplotlib/mpl-data/stylelib/_classic_test_patch.mplstyle. You probably need to get an updated matplotlibrc file from https://github.com/matplotlib/matplotlib/blob/v3.1.3/matplotlibrc.template..
2022.02.07
[Solution][Pytorch] RuntimeError: Error(s) in loading state_dict for ... : Missing key(s) in state_dict: ... Unexpected key(s) in state_dict: ...
2021.01.23
Boostcamp AI Tech 3기 Pre-Co..
(4)
컴퓨터비전, 머신러닝, 딥러닝을 이용한 의료영상분..
(65)
Youtube - Steve Brunton
(1)
Upstage (개인: 열람불가)
(0)
Image Processing
(1)
AI 관련 사이트
(4)
Python
(59)