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

報錯緣由:numpy不能讀取CUDA tensor 須要將它轉化爲 CPU tensor。code

因此若是想把CUDA tensor格式的數據改爲numpy時,須要先將其轉換成cpu float-tensor隨後再轉到numpy格式blog

報錯行:get

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

修改後:class

tcls[index, best_n, g_y_center, g_x_center, np.array(target[index, t, 0].cpu())] = 1
相關文章
相關標籤/搜索