본문 바로가기
Error Note

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor,,,

by ga.0_0.ga 2023. 1. 30.
728x90
반응형
반응형

- 전체 에러 문구

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

GPU에 할당된 텐서를 numpy 배열로 변환할 때 발생하는 에러입니다. 텐서 x를 np.array(x)로 변환할 때 발생합니다.

- 해결 방법

문제가 되는 텐서를 cpu()함수를 이용해 CPU 텐서로 변환해주면 됩니다.

x = x.cpu()  ##  CPU로 변환
x = np.array(x)  ## numpy로 변환

 

728x90
반응형

댓글