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

报错原因: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

 

转载于:https://www.cnblogs.com/xiaodai0/p/10677363.html

你可能感兴趣的:(python)