TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
구현 중에, 위와 같은 에러가 발생하였다.
재현
import torch
a = torch.tensor(1)
a = a.cuda()
a.numpy()
이 에러는 GPU에 올린 Tensor를 바로 numpy로 변환하였을 때 발생한다.
따라서, 다음과 같은 방법으로 해결된다.
import torch
a = torch.tensor(1)
a = a.cuda()
a.cpu().numpy()
cpu method를 사용해 cpu ram에 로드하고, numpy method를 사용해주었다.
'다시 보기 싫은 에러 정리' 카테고리의 다른 글
Excel "리소스가 부족하여 하나 이상의 수식을 계산할 수 없습니다" 에러 문제 해결 + 긴 로딩 시간과 엑셀 프리징 현상 완화 방법 (0) | 2023.02.09 |
---|---|
JAX GPU 메모리 사용량 문제 (JAX Preallocate) (0) | 2022.09.14 |