rosinality / stylegan2-pytorch

Implementation of Analyzing and Improving the Image Quality of StyleGAN (StyleGAN 2) in PyTorch
MIT License
2.73k stars 620 forks source link

How to use conv2d_gradfix in high version? #252

Open Feywell opened 3 years ago

Feywell commented 3 years ago

I try to use my own dataset. But there is a warning here?

0%| | 0/800000 [00:00<?, ?it/s]/project/GAN/stylegan2-pytorch/op/conv2d_gradfix.py:89: UserWarning: conv2d_gradfix not supported on PyTorch 1.6.0. Falling back to torch.nn.functional.conv2d(). f"conv2d_gradfix not supported on PyTorch {torch.version}. Falling back to torch.nn.functional.conv2d()."

What can I change to make the code work? Thank you!

rosinality commented 3 years ago

You need to use pytorch 1.7+.

Feywell commented 3 years ago

But I use pytorch 1.9. The warning is same.

project/experiment/stylegan2/op/conv2d_gradfix.py:89: UserWarning: conv2d_gradfix not supported on PyTorch 1.9.0. Falling back to torch.nn.functional.conv2d(). f"conv2d_gradfix not supported on PyTorch {torch.version}. Falling back to torch.nn.functional.conv2d()."

rosinality commented 3 years ago

I haven't test it on pytorch 1.9, but I think you can add it to https://github.com/rosinality/stylegan2-pytorch/blob/master/op/conv2d_gradfix.py#L85 this line and I guess it will work.

LonglongaaaGo commented 1 year ago

Hi @rosinality , Would that hurt the generation quality if I directly use the torch.nn.functional.conv2d() instead of the conv2d_gradfix? I am waiting for your reply! Thank you!

exceedzhang commented 1 year ago

I haven't test it on pytorch 1.9, but I think you can add it to https://github.com/rosinality/stylegan2-pytorch/blob/master/op/conv2d_gradfix.py#L85 this line and I guess it will work.

I also found similar problems, and I also used pytorch 1.12.1

image

python finetune_stylegan.py --iter 600 --batch 4 --size 1024 --ckpt ./checkpoint/stylegan2-ffhq-config-f.pt --style fantasy --augment ./data/fantasy/lmdb/ Load options ada_every: 256 ada_length: 500000 ada_target: 0.6 augment: True augment_p: 0 batch: 4 channel_multiplier: 2 ckpt: ./checkpoint/stylegan2-ffhq-config-f.pt d_reg_every: 16 g_reg_every: 4 iter: 600 local_rank: 0 lr: 0.002 mixing: 0.9 model_path: ./checkpoint/ n_sample: 9 path: ./data/fantasy/lmdb/ path_batch_shrink: 2 path_regularize: 2 r1: 10 save_every: 10000 size: 1024 style: fantasy wandb: False


load model: ./checkpoint/stylegan2-ffhq-config-f.pt 0%| | 0/600 [00:00<?, ?it/s]/root/DualStyleGAN/model/stylegan/op/conv2d_gradfix.py:88: UserWarning: conv2d_gradfix not supported on PyTorch 1.12.1. Falling back to torch.nn.functional.conv2d(). warnings.warn( 0%| | 0/600 [00:02<?, ?it/s] Traceback (most recent call last): File "finetune_stylegan.py", line 391, in train(args, loader, generator, discriminator, g_optim, d_optim, g_ema, device) File "finetune_stylegan.py", line 159, in train r1_loss = d_r1_loss(real_pred, real_img) File "/root/DualStyleGAN/util.py", line 71, in d_r1_loss grad_real, = autograd.grad( File "/opt/miniconda3/envs/vtoonify/lib/python3.8/site-packages/torch/autograd/init.py", line 276, in grad return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass File "/opt/miniconda3/envs/vtoonify/lib/python3.8/site-packages/torch/autograd/function.py", line 253, in apply return user_fn(self, *args) File "/root/DualStyleGAN/model/stylegan/non_leaking.py", line 352, in backward grad_input, grad_grid = GridSampleBackward.apply(grad_output, input, grid) File "/root/DualStyleGAN/model/stylegan/non_leaking.py", line 361, in forward grad_input, grad_grid = op(grad_output, input, grid, 0, 0, False) TypeError: 'tuple' object is not callable