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

Error in transforming custom image script, and error in running the program script (to generate images and videos) #154

Open
ayaderaghul opened this issue Apr 17, 2023 · 5 comments

Comments

@ayaderaghul
Copy link

ayaderaghul commented Apr 17, 2023

In google Colab, I run this script to transform custom images:

!python main.py --mode align \
               --inp_dir assets/representative/custom/female \
               --out_dir assets/representative/celeba_hq/src/female

and have this error

Namespace(img_size=256, num_domains=2, latent_dim=16, hidden_dim=512, style_dim=64, lambda_reg=1, lambda_cyc=1, lambda_sty=1, lambda_ds=1, ds_iter=100000, w_hpf=1, randcrop_prob=0.5, total_iters=100000, resume_iter=0, batch_size=8, val_batch_size=32, lr=0.0001, f_lr=1e-06, beta1=0.0, beta2=0.99, weight_decay=0.0001, num_outs_per_domain=10, mode='align', num_workers=4, seed=777, train_img_dir='data/celeba_hq/train', val_img_dir='data/celeba_hq/val', sample_dir='expr/samples', checkpoint_dir='expr/checkpoints', eval_dir='expr/eval', result_dir='expr/results', src_dir='assets/representative/celeba_hq/src', ref_dir='assets/representative/celeba_hq/ref', inp_dir='assets/representative/custom/female', out_dir='assets/representative/celeba_hq/src/female', wing_path='expr/checkpoints/wing.ckpt', lm_path='expr/checkpoints/celeba_lm_mean.npz', print_every=10, sample_every=5000, save_every=10000, eval_every=50000)
Number of parameters of generator: 43467395
Number of parameters of mapping_network: 2438272
Number of parameters of style_encoder: 20916928
Number of parameters of discriminator: 20852290
Number of parameters of fan: 6333603
Initializing generator...
Initializing mapping_network...
Initializing style_encoder...
Initializing discriminator...
Traceback (most recent call last):
  File "/content/stargan-v2/main.py", line 182, in <module>
    main(args)
  File "/content/stargan-v2/main.py", line 78, in main
    align_faces(args, args.inp_dir, args.out_dir)
  File "/content/stargan-v2/core/wing.py", line 427, in align_faces
    x_aligned = aligner.align(x)
  File "/content/stargan-v2/core/wing.py", line 305, in align
    img_np, landmarks = pad_mirror(img_np, landmarks)
  File "/content/stargan-v2/core/wing.py", line 392, in pad_mirror
    small_blurred = gaussian(cv2.resize(img, (W, H)), H//100, multichannel=True)
TypeError: gaussian() got an unexpected keyword argument 'multichannel'

Similarly, I run the script to generate images and videos

!python main.py --mode sample --num_domains 2 --resume_iter 100000 --w_hpf 1 \
               --checkpoint_dir expr/checkpoints/celeba_hq \
               --result_dir expr/results/celeba_hq \
               --src_dir assets/representative/celeba_hq/src \
               --ref_dir assets/representative/celeba_hq/ref

and it has the following error

Namespace(img_size=256, num_domains=2, latent_dim=16, hidden_dim=512, style_dim=64, lambda_reg=1, lambda_cyc=1, lambda_sty=1, lambda_ds=1, ds_iter=100000, w_hpf=1.0, randcrop_prob=0.5, total_iters=100000, resume_iter=100000, batch_size=8, val_batch_size=32, lr=0.0001, f_lr=1e-06, beta1=0.0, beta2=0.99, weight_decay=0.0001, num_outs_per_domain=10, mode='sample', num_workers=4, seed=777, train_img_dir='data/celeba_hq/train', val_img_dir='data/celeba_hq/val', sample_dir='expr/samples', checkpoint_dir='expr/checkpoints/celeba_hq', eval_dir='expr/eval', result_dir='expr/results/celeba_hq', src_dir='assets/representative/celeba_hq/src', ref_dir='assets/representative/celeba_hq/ref', inp_dir='assets/representative/custom/female', out_dir='assets/representative/celeba_hq/src/female', wing_path='expr/checkpoints/wing.ckpt', lm_path='expr/checkpoints/celeba_lm_mean.npz', print_every=10, sample_every=5000, save_every=10000, eval_every=50000)
Number of parameters of generator: 43467395
Number of parameters of mapping_network: 2438272
Number of parameters of style_encoder: 20916928
Number of parameters of discriminator: 20852290
Number of parameters of fan: 6333603
Initializing generator...
Initializing mapping_network...
Initializing style_encoder...
Initializing discriminator...
Preparing DataLoader for the generation phase...
/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py:561: UserWarning: This DataLoader will create 4 worker processes in total. Our suggested max number of worker in current system is 2, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary.
  warnings.warn(_create_warning_msg(
Preparing DataLoader for the generation phase...
Loading checkpoint from expr/checkpoints/celeba_hq/100000_nets_ema.ckpt...
Traceback (most recent call last):
  File "/content/stargan-v2/main.py", line 182, in <module>
    main(args)
  File "/content/stargan-v2/main.py", line 73, in main
    solver.sample(loaders)
  File "/usr/local/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/content/stargan-v2/core/solver.py", line 178, in sample
    self._load_checkpoint(args.resume_iter)
  File "/content/stargan-v2/core/solver.py", line 73, in _load_checkpoint
    ckptio.load(step)
  File "/content/stargan-v2/core/checkpoint.py", line 48, in load
    module.module.load_state_dict(module_dict[name])
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2041, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Generator:
	Missing key(s) in state_dict: "hpf.filter". 
@FantasticZihao
Copy link

@ayaderaghul 在运行时报错的那个地方load_state_dict函数括号中加一个strict=False

@ayaderaghul
Copy link
Author

@ayaderaghul 在运行时报错的那个地方load_state_dict函数括号中加一个strict=False

@FantasticZihao and the first one?

@FantasticZihao
Copy link

@ayaderaghul It's an TypeError. I didn't meet sunch a situation. I think maybe "multichannel" doesn't match the type of function gaussian.

@ayaderaghul
Copy link
Author

I was thinking it is because of the new versions of libraries

@SubeBila
Copy link

Hi, I'm having the same problem as you. Can you please tell me if you have finally solved this problem and if it would be convenient to tell me how to solve this problem. I will be very grateful for your answer.

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