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

About NAN during training #51

Open
yjh0410 opened this issue May 3, 2022 · 1 comment
Open

About NAN during training #51

yjh0410 opened this issue May 3, 2022 · 1 comment

Comments

@yjh0410
Copy link

yjh0410 commented May 3, 2022

@chensnathan

I think the following passage may be the main cause of the NAN problem:

normalized_cls_score = cls_score + objectness - torch.log(
1. + torch.clamp(cls_score.exp(), max=self.INF) + torch.clamp(
objectness.exp(), max=self.INF))

There is an exp operation in this code, and clip is used to clip it to avoid explosion, but this still has hidden dangers, that is, before clipping, the exp may have exploded and overflowed, so the clip is useless at this time.

So, I changed to clip first and then exp,:

normalized_cls_pred = cls_pred + obj_pred - torch.log(
1. +
torch.clamp(cls_pred, max=DEFAULT_EXP_CLAMP).exp() +
torch.clamp(obj_pred, max=DEFAULT_EXP_CLAMP).exp())
where DEFAULT_EXP_CLAMP = log(INF).

After above modification, NAN problem no longer encountered.

@ytoon
Copy link
Collaborator

ytoon commented May 25, 2022

Thanks for your suggestion, we will check it. If so, we will update our code with it.

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

2 participants