can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
- 
발생 위치 train_accuracy(y, prediction)를 실행하는 중에 발생 
 
- 
발생 원인 함수 내에서 prediction을 numpy의 array로 바꿔주는데 현재 prediction이 gpu에 할당되어 있어 문제가 발생하는 것이다. 즉, gpu에 할당되어 있는 텐서값을 numpy배열로 바꿀때 발생하는 에러이다. 
 
- 
해결 방법 gpu로 할당되어 있는 텐서를 cpu 텐서로 바꿔주면 된다. #support X si GPU tensor X.numpy # this cause error X.cpu().numpy()위에 명령어를 실행할 경우 Can not squeeze dim[1], expected a dimension of 1, got 30 [Op:Squeeze] cpu로 바꿔줬을 때, 이와 같은 에러가 다시 발생했다. 이경우는 차원의 문제로 기대값은 1차원의 값이나 30차원의 값이 들어옴으로써 발생하는 에러였다. 따라서 예측값 중 가장 유사도(?)가 높은 값을 찾아 하나의 값만 인자로 넘겨주면 해결할 수 있다. y = y.cpu() prediction = prediction.cpu() train_accuracy(y, prediction.argmax(0))
Author And Source
이 문제에 관하여(can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@xdfc1745/cant-convert-cuda0-device-type-tensor-to-numpy.-Use-Tensor.cpu-to-copy-the-tensor-to-host-memory-first저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)