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


報錯原因:numpy不能讀取CUDA tensor 需要將它轉化為 CPU tensor。

所以如果想把CUDA tensor格式的數據改成numpy時,需要先將其轉換成cpu float-tensor隨后再轉到numpy格式

報錯行:

tcls[index, best_n, g_y_center, g_x_center, np.array(target[index, t, 0])] = 1

修改后:

tcls[index, best_n, g_y_center, g_x_center, np.array(target[index, t, 0].cpu())] = 1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM