Pytorch——报错解决:RuntimeError: Expected all tensors to be on the same device, but found at least two devices
一、报错信息
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument weight in method wrapper_nll_loss_forward)
二、报错原因
tensors 一会在CPU运算,一会在GPU运算。
三、解决方法
都改成在GPU运算。
四、原代码