stylegan-xl icon indicating copy to clipboard operation
stylegan-xl copied to clipboard

Discriminator pre-train models missing parameters

Open KaixuanZ opened this issue 2 years ago • 3 comments

I am using both the generator and discriminator. Generator works well but the discriminator doesn't. Here is part of my code:

////////////load D and G with dnnlib.util.open_url(network_pkl) as f: D = legacy.load_network_pkl(f)['D'] D = D.eval().requires_grad_(False).to(device)

with dnnlib.util.open_url(network_pkl) as f: G = legacy.load_network_pkl(f)['G_ema'] G = G.eval().requires_grad_(False).to(device)

img = G.synthesis(w, update_emas=False) D(img, torch.empty([1, G.c_dim], device=device)) ////////////////

Error happened in the last line of code. I tried different pre-trained models, some time the error is missing AttributeError: 'Mlp' object has no attribute 'drop1', sometimes is missing "mean" and "std" for normalization layer.

Here is one error message:

/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/torch/functional.py:568: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2228.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] Traceback (most recent call last): File "/home/kaixuan/Projects/MyStyleGAN_XL/D_run_tmp.py", line 136, in generate_images() # pylint: disable=no-value-for-parameter File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/click/core.py", line 1130, in call return self.main(*args, **kwargs) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/click/core.py", line 760, in invoke return __callback(*args, **kwargs) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "/home/kaixuan/Projects/MyStyleGAN_XL/D_run_tmp.py", line 129, in generate_images D(img1, torch.empty([1, G.c_dim], device=device)) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/home/kaixuan/Projects/MyStyleGAN_XL/pg_modules/discriminator.py", line 213, in forward features = feat(x_n) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/home/kaixuan/Projects/MyStyleGAN_XL/pg_modules/projector.py", line 114, in forward out0, out1, out2, out3 = forward_vit(self.pretrained, x) File "/home/kaixuan/Projects/MyStyleGAN_XL/feature_networks/vit.py", line 59, in forward_vit _ = pretrained.model.forward_flex(x) File "/home/kaixuan/Projects/MyStyleGAN_XL/feature_networks/vit.py", line 149, in forward_flex x = blk(x) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/timm/models/vision_transformer.py", line 230, in forward x = x + self.drop_path(self.mlp(self.norm2(x))) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/timm/models/layers/mlp.py", line 28, in forward x = self.drop1(x) File "/home/kaixuan/anaconda3/envs/GAN/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1185, in getattr raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'Mlp' object has no attribute 'drop1'

KaixuanZ avatar May 20 '22 00:05 KaixuanZ

Which version of timm are you using in your environment?

xl-sr avatar Jun 10 '22 12:06 xl-sr

Thanks for your reply!

I was using timm=0.5.4 and I have re-installed the environment to make sure it's the same as the .yml file

However, I am still unable to use the discriminator, with the same piece of code, now I get following error: TypeError: 'NoneType' object is not subscriptable

KaixuanZ avatar Jun 17 '22 06:06 KaixuanZ

Thanks for your reply!

I was using timm=0.5.4 and I have re-installed the environment to make sure it's the same as the .yml file

However, I am still unable to use the discriminator, with the same piece of code, now I get following error: TypeError: 'NoneType' object is not subscriptable

hello, I meet the same question: 'NoneType' object is not subscriptable, if you slove it, can you tell me how to slove? thanks

Sprite137 avatar Oct 14 '23 11:10 Sprite137