clovaai / stargan-v2

StarGAN v2 - Official PyTorch Implementation (CVPR 2020)
Other
3.47k stars 653 forks source link

UnBoundLocalError #28

Open iPsych opened 4 years ago

iPsych commented 4 years ago

Similar to issue #11

After train, eval error happens when use 4 domains dataset.

Should I adjust lambda_ds for #domains-1, or adjust other variable to fit with # of domains?

python main.py --mode train --num_domains 4 --w_hpf 0 \
               --lambda_reg 1 --lambda_sty 1 --lambda_ds 1 --lambda_cyc 1 \
               --train_img_dir data/custom/train \
               --val_img_dir data/custom/val
Calculating evaluation metrics...
Number of domains: 4
Preparing DataLoader for the evaluation phase...
Traceback (most recent call last):
  File "main.py", line 182, in <module>
    main(args)
  File "main.py", line 59, in main
    solver.train(loaders)
  File "/home/ipsych/ML/Stargan_v2/core/solver.py", line 170, in train
    calculate_metrics(nets_ema, args, i+1, mode='latent')
  File "/home/ipsych/.conda/envs/Pytorch_1_4_0/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad
    return func(*args, **kwargs)
  File "/home/ipsych/ML/Stargan_v2/metrics/eval.py", line 61, in calculate_metrics
    iter_ref = iter(loader_ref)
UnboundLocalError: local variable 'loader_ref' referenced before assignment
yunjey commented 4 years ago

@iPsych Please use the updated code. This commit should resolve the error.

Johnson-yue commented 4 years ago

@yunjey I try This commit and it fixed "StopIterationError" but not fix "UnboundLocalError" , as my test

iPsych commented 4 years ago

@yunjey @Johnson-yue I am experiencing same issue related to loader_ref.

Johnson-yue commented 4 years ago

@iPsych I know that ,and I have same issue, maybe it was caused by different num_domains

iPsych commented 4 years ago

@yunjey Hi, Does number of domains, or number of images for eval (currently very smaller than train images) can cause the problem?

iPsych commented 4 years ago

Mistakenly put the stopiteration error in here.

Johnson-yue commented 4 years ago

@iPsych This is StopIteration Error not UnBoundLocalError and StopIteration Error was fixed in This commit I have checked . So maybe you upload false log ???

iPsych commented 4 years ago

@Johnson-yue My bad.. The UnBoundLocalError disappeared, but StopIteration happens even with latest commit and latest sources.

iPsych commented 4 years ago

@Johnson-yue, @yunjey I again face with the UnBoundLocalError with latest code. I patched eval.py with https://github.com/clovaai/stargan-v2/pull/9 but still face below errors.

3781] G/ref_sty: [0.1911] G/ref_ds: [0.6815] G/ref_cyc: [0.2138] G/lambda_ds: [1.8000]
Saving checkpoint into expr/checkpoints/050000_nets.ckpt...
Saving checkpoint into expr/checkpoints/050000_nets_ema.ckpt...
Saving checkpoint into expr/checkpoints/050000_optims.ckpt...
Calculating evaluation metrics...
Number of domains: 3
Preparing DataLoader for the evaluation phase...
Traceback (most recent call last):
  File "main.py", line 182, in <module>
    main(args)
  File "main.py", line 59, in main
    solver.train(loaders)
  File "/home/ipsych/ML/stargan-v2/core/solver.py", line 170, in train
    calculate_metrics(nets_ema, args, i+1, mode='latent')
  File "/home/ipsych/.conda/envs/Pytorch_1_4_0/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad
    return func(*args, **kwargs)
  File "/home/ipsych/ML/stargan-v2/metrics/eval.py", line 61, in calculate_metrics
    iter_ref = iter(loader_ref)
UnboundLocalError: local variable 'loader_ref' referenced before assignment
1170300814 commented 2 years ago

i also have this error and use the lattest version of eval.py. how to solve it ?

1170300814 commented 2 years ago

@yunjey that commit doesn't solve it

aliwaqas333 commented 1 year ago

setting --val_batch_size=1 solves the issue.