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