lyndonzheng / Pluralistic-Inpainting

[CVPR 2019]: Pluralistic Image Completion
672 stars 144 forks source link

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! #54

Closed n00mkrad closed 3 years ago

n00mkrad commented 3 years ago

I get this error trying to run the train script on Windows:

Traceback (most recent call last):
  File "train.py", line 35, in <module>
    model.optimize_parameters()
  File "D:\AI\Pluralistic-Inpainting\model\pluralistic_model.py", line 224, in optimize_parameters
    self.forward()
  File "D:\AI\Pluralistic-Inpainting\model\pluralistic_model.py", line 140, in forward
    p_distribution, q_distribution, self.kl_rec, self.kl_g = self.get_distribution(distributions)
  File "D:\AI\Pluralistic-Inpainting\model\pluralistic_model.py", line 107, in get_distribution
    m_distribution = torch.distributions.Normal(torch.zeros_like(p_mu), m_sigma * torch.ones_like(p_sigma))
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

How can I avoid this?
I'm trying to train on a single GPU.

lyndonzheng commented 3 years ago

Hi @n00mkrad, the original code is under the Pytorch V0.4. I am not sure whether this error comes from different versions of Pytorch. As the error is clear that you have some tensors on different devices, you can check/debug the device of these tensors.