danielroich / PTI

Official Implementation for "Pivotal Tuning for Latent-based editing of Real Images" (ACM TOG 2022) https://arxiv.org/abs/2106.05744
MIT License
897 stars 112 forks source link

run_pit: assert target.shape == (G.img_channels, G.img_resolution, G.img_resolution) #48

Closed FrancescoSaverioZuppichini closed 1 year ago

FrancescoSaverioZuppichini commented 1 year ago

Hi there 👋

Thanks a lot for the project, I trying to use run_pti with an image but I got this error

(stylegan3) ➜  PTI git:(main) ✗ python scripts/run_pti.py
Setting up [LPIPS] perceptual loss: trunk [alex], v[0.1], spatial [off]
/home/zuppif/miniconda3/envs/stylegan3/lib/python3.9/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
  warnings.warn(
/home/zuppif/miniconda3/envs/stylegan3/lib/python3.9/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=AlexNet_Weights.IMAGENET1K_V1`. You can also use `weights=AlexNet_Weights.DEFAULT` to get the most up-to-date weights.
  warnings.warn(msg)
Loading model from: /home/zuppif/miniconda3/envs/stylegan3/lib/python3.9/site-packages/lpips/weights/v0.1/alex.pth
  0%|                                                                             | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/home/zuppif/Documents/DragGAN/PTI/scripts/run_pti.py", line 51, in <module>
    run_PTI(run_name='', use_wandb=False, use_multi_id_training=False)
  File "/home/zuppif/Documents/DragGAN/PTI/scripts/run_pti.py", line 45, in run_PTI
    coach.train()
  File "/home/zuppif/Documents/DragGAN/PTI/training/coaches/single_id_coach.py", line 39, in train
    w_pivot = self.calc_inversions(image, image_name)
  File "/home/zuppif/Documents/DragGAN/PTI/training/coaches/base_coach.py", line 93, in calc_inversions
    w = w_projector.project(self.G, id_image, device=torch.device(global_config.device), w_avg_samples=600,
  File "/home/zuppif/Documents/DragGAN/PTI/training/projectors/w_projector.py", line 41, in project
    assert target.shape == (G.img_channels, G.img_resolution, G.img_resolution)
AssertionError

I first try to resize the image to 1024x512 then to 1024x1024 but the error persist.

Thanks a lot

Fra

FrancescoSaverioZuppichini commented 1 year ago

I've printed target.shape and G.img_channels, G.img_resolution, G.img_resolution

torch.Size([3, 570, 728]), 3 1024 1024
FrancescoSaverioZuppichini commented 1 year ago

ops the target image was not 1024x1024 😓

Since I am here, I'd like to ask the best way to resize the image to preserve aspect ration and run it with run_pti

danielroich commented 1 year ago

Hi @FrancescoSaverioZuppichini, To my knowledge bilinear interpolation or quadratic interpolation(if you have the time) works pretty good