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

UnboundLocalError: local variable 'val_loss_epoch' referenced before assignment #2

Open
minho8849 opened this issue Aug 30, 2021 · 10 comments

Comments

@minho8849
Copy link

I want to train this code for dataset, following as

$ python tools/train.py --data_root /home/my_com/dataset/KITTI/ --batch_size 4

when first epoch is done, I got error

Traceback (most recent call last):
File "tools/train.py", line 164, in
main()
File "tools/train.py", line 157, in main
val_loader
File "/home/my_com/virtualenv/JMODT/jmodt/utils/train_utils.py", line 198, in train
prev_val_loss = val_loss_epoch

Can I get some solution from this problem?

Thanks.

@Bruce-Si
Copy link

Bruce-Si commented Oct 8, 2021

I want to train this code for dataset, following as

$ python tools/train.py --data_root /home/my_com/dataset/KITTI/ --batch_size 4

when first epoch is done, I got error

Traceback (most recent call last): File "tools/train.py", line 164, in main() File "tools/train.py", line 157, in main val_loader File "/home/my_com/virtualenv/JMODT/jmodt/utils/train_utils.py", line 198, in train prev_val_loss = val_loss_epoch

Can I get some solution from this problem?

Thanks.

I get the same error. Is there any progress?

@Lemon-L7
Copy link

Lemon-L7 commented Oct 12, 2021

I want to train this code for dataset, following as
$ python tools/train.py --data_root /home/my_com/dataset/KITTI/ --batch_size 4
when first epoch is done, I got error
Traceback (most recent call last): File "tools/train.py", line 164, in main() File "tools/train.py", line 157, in main val_loader File "/home/my_com/virtualenv/JMODT/jmodt/utils/train_utils.py", line 198, in train prev_val_loss = val_loss_epoch
Can I get some solution from this problem?
Thanks.

I get the same error. Is there any progress?

I get the same error. Is there any progress? I means how to get the sample2frame.txt & seq2sample.txt in TESTING file

@Bruce-Si

@Bruce-Si
Copy link

I have not noticed this problem... The script kitti_converter.py just creates TRAINING file. Maybe we have to create TESTING file by imitating the kitti_converter.py.
@Lemon-L7

@Lemon-L7
Copy link

yeap,I check the files, if author‘s code didn't has any trouble, we should create TESTING file, like he sets in his constructor. @Bruce-Si

@ferrari700
Copy link

yeap,I check the files, if author‘s code didn't has any trouble, we should create TESTING file, like he sets in his constructor. @Bruce-Si

Hello, I also encountered the same problem, have you solved it? How is the testing file created?

@zzm-hl
Copy link

zzm-hl commented Mar 7, 2022

我想为数据集训练此代码,如下所示

$ python 工具/train.py --data_root /home/my_com/dataset/KITTI/ --batch_size 4

当第一个时代完成时,我得到了错误

回溯(最后一次调用): 文件“tools/train.py”,第 164 行,在 main() 文件“tools/train.py”,第 157 行,在 main val_loader 文件“/home/my_com/virtualenv/JMODT/ jmodt/utils/train_utils.py",第 198 行,在火车 prev_val_loss = val_loss_epoch

我可以从这个问题中得到一些解决方案吗?

谢谢。

I have the same problem ,have you solved it? @Kemo-Huang @minho8849

@lx-ynu
Copy link

lx-ynu commented Mar 13, 2022

After I assigned an initial value to "val_loss_epoch", the network can be trained, but there is another problem, the "best_model" will not be updated after the first epoch is trained.

@zkp0113
Copy link

zkp0113 commented Mar 16, 2022

@Kemo-Huang
Excuse me,I meet same problems.
No.1 ”UnboundLocalError: local variable 'val_loss_epoch' referenced before assignment“;
For this problem I change some code then the problem fixed,but it comes new problem that same with this.

No.2 “best_model.path” is not update.

对不起,我也遇到同样的问题。
第1条问 “UnboundLocalError:赋值前引用的局部变量‘val_loss_epoch’”;对于这个问题,我更改了一些代码,然后问题得到了解决,但随之而来的是新问题。
第2条 “best_model.path”未更新。

This was referenced Mar 17, 2022
@sazanali
Copy link

add the following line for solution
def train(self, start_it, start_epoch, n_epochs, train_loader, val_loader=None, stop_thres=5):
eval_frequency = self.eval_frequency if self.eval_frequency > 0 else 1
global val_loss_epoch
global prev_train_loss
global prev_val_loss

in the bottom

else:
prev_train_loss = train_loss_epoch
prev_val_loss = val_loss_epoch

            val_loss_epoch =1
            if val_loss_epoch < min_val_loss:
                min_val_loss = val_loss_epoch

@sazanali
Copy link

Any solution for best_model.path???

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

8 participants