Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an error 'tensor is not a torch image.' when trying to run train.py #18

Closed
samotiian opened this issue Sep 28, 2021 · 9 comments

Comments

@samotiian
Copy link

Initializing networks...
  0%|                                                                                                             | 0/301 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "train.py", line 147, in <module>
    train(args)
  File "train.py", line 86, in train
    [sampled_src, sampled_dst], loss = net(sample_z)
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/ubuntu/efs/saeid/facelab/StyleGAN-nada/ZSSGAN/model/ZSSGAN.py", line 260, in forward
    train_layers = self.determine_opt_layers()
  File "/home/ubuntu/efs/saeid/facelab/StyleGAN-nada/ZSSGAN/model/ZSSGAN.py", line 216, in determine_opt_layers
    w_loss = [self.clip_model_weights[model_name] * self.clip_loss_models[model_name].global_clip_loss(generated_from_w, self.target_class) for model_name in self.clip_model_weights.keys()]
  File "/home/ubuntu/efs/saeid/facelab/StyleGAN-nada/ZSSGAN/model/ZSSGAN.py", line 216, in <listcomp>
    w_loss = [self.clip_model_weights[model_name] * self.clip_loss_models[model_name].global_clip_loss(generated_from_w, self.target_class) for model_name in self.clip_model_weights.keys()]
  File "/home/ubuntu/efs/saeid/facelab/StyleGAN-nada/ZSSGAN/criteria/clip_loss.py", line 190, in global_clip_loss
    image  = self.preprocess(img)
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 60, in __call__
    img = t(img)
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 163, in __call__
    return F.normalize(tensor, self.mean, self.std, self.inplace)
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 201, in normalize
    raise TypeError('tensor is not a torch image.')
TypeError: tensor is not a torch image.
@rinongal
Copy link
Owner

Hi,

A few questions:

  1. Are you running our code as is? Did you modify anything?
  2. What arguments did you use when running the script?
  3. Are you starting from one of the official StyleGAN2 models? If not, what model are you using? Does it load correctly and output images when using Rosinality's StyleGAN2 implementation?

@samotiian
Copy link
Author

Hello.

  1. I did not modify anything.
  2. The default args in the repo.
  3. I think the stylegan2 weights are ok. Because I can generate images using the weights.

@rinongal
Copy link
Owner

I'm having no luck reproducing the error with the default args from the readme.

Just to make sure:

  1. What pytorch version are you using?
  2. If you're using 1.7.1 or above, can you try to run the code with the official FFHQ model (here) or with one of our trained models just so we can rule out the model file? Alternatively if the model you are using is public, give me the link and I'll see if using it lets me reproduce the issue.

@duxiaodan
Copy link

I ran into the same problem. You are likely using torchvision=0.2.x. Early versions of torchvison don't support doing normalization over a 4D tensor. Try to upgrade to 0.8.x and it should work.

@rinongal
Copy link
Owner

@samotiian Did @duxiaodan's solution resolve your problem?

@samotiian
Copy link
Author

I upgraded the torchvision and it is not working. Thanks

@rinongal
Copy link
Owner

Could you let me know what torch, torchvision, and cuda versions you're running? I'll try to recreate the environment and see if I can reproduce the issue.

@samotiian
Copy link
Author

I do not remember what environment I used when I got that error.

@rinongal
Copy link
Owner

I'm closing this due to lack of activity. If you still have an error and need help, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants