mingyuliutw / UNIT

Unsupervised Image-to-Image Translation
Other
1.98k stars 360 forks source link

RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #3 'other' #74

Closed doantientai closed 5 years ago

doantientai commented 6 years ago

Hi,

I am trying to implement the network on my own data-set, but received the error. I don't know where does it come from. Please help. Thank you a lot!

Traceback (most recent call last):
  File "train.py", line 65, in <module>
    trainer.gen_update(images_a, images_b, config)
  File "/media/tai/6TB/Projects/UNIT/trainer.py", line 295, in gen_update
    self.loss_gen_vgg_a = self.compute_vgg_loss(self.vgg, x_ba, x_b) if hyperparameters['vgg_w'] > 0 else 0
  File "/media/tai/6TB/Projects/UNIT/trainer.py", line 314, in compute_vgg_loss
    img_vgg = vgg_preprocess(img)
  File "/media/tai/6TB/Projects/UNIT/utils.py", line 244, in vgg_preprocess
    batch = batch.sub(Variable(mean)) # subtract mean
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #3 'other'
mingyuliutw commented 6 years ago

Based on the error message, it seems like you forgot to call .cuda for your tensor.

p-geon commented 6 years ago

@doantientai It seems to occured in Line 244 of utils.py. You should modify the code below.

batch = batch.sub(Variable(mean)) # subtract mean to batch = batch.sub(Variable(mean).cuda()) # subtract mean