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

fix the bug-[local variable 'iter_ref' referenced before assignment] #9

Closed
wants to merge 1 commit into from

Conversation

Johnson-yue
Copy link

it report StopIteration Error

@iPsych
Copy link

iPsych commented May 13, 2020

@yunjey with latest source, I am facing same error.
Below is full log

Preparing DataLoader for the evaluation phase...
Preparing DataLoader for the evaluation phase...
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:02<00:00, 8.97it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 4.06it/s]
Calculating evaluation metrics...
Number of domains: 4
Preparing DataLoader for the evaluation phase...
Preparing DataLoader for the evaluation phase...
Generating images and calculating LPIPS for Happy2Fear...
0%| | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/home/ipsych/ML/stargan-v2/metrics/eval.py", line 76, in calculate_metrics
x_ref = next(iter_ref).to(device)
UnboundLocalError: local variable 'iter_ref' referenced before assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 182, in
main(args)
File "main.py", line 59, in main
solver.train(loaders)
File "/home/ipsych/ML/stargan-v2/core/solver.py", line 171, in train
calculate_metrics(nets_ema, args, i+1, mode='reference')
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 79, in calculate_metrics
x_ref = next(iter_ref).to(device)
File "/home/ipsych/.conda/envs/Pytorch_1_4_0/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 345, in next
data = self._next_data()
File "/home/ipsych/.conda/envs/Pytorch_1_4_0/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 831, in _next_data
raise StopIteration
StopIteration
I trained with custom dataset named EMO-S consists of four domains with below codes.

python main.py --mode train --num_domains 4 --w_hpf 0 --lambda_reg 1 --lambda_sty 1 --lambda_ds 3 --lambda_cyc 1 --train_img_dir ./data/EMO-S/train --val_img_dir ./data/EMO-S/val

@Johnson-yue Johnson-yue deleted the patch-1 branch May 14, 2020 02:12
@iPsych iPsych mentioned this pull request May 19, 2020
Copy link

@doantientai doantientai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line iter_ref = iter(loader_ref) should be inside the condition if mode == 'reference'. Otherwise, it will crash the program because loader_ref is used before being defined.

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

Successfully merging this pull request may close these issues.

3 participants