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 iou precision error #1592

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

fix iou precision error #1592

wants to merge 2 commits into from

Conversation

h-bo
Copy link

@h-bo h-bo commented Jan 13, 2023

currently, when cal iou, yolox use float16 (in float16 mode), but float16 only has 10 bits for valid part this may lead iou precision error:
for example torch.tensor(841, dtype=float16) - torch.tensor(5.2, dtype=float16) ==torch.tensor(836., dtype=torch.float16).

this can lead iou to be larger than 1 and in cls loss, yolox multiplies target with iou, so that the bce loss can be negtive!

change iou calculation to float32 seems to fix that
image
image

currently, when cal iou, yolox use float16 (in float16 mode), but float16 only has 10 bits for valid part
this may lead iou precision error, for example torch.tensor(841, dtype=float16) -  torch.tensor(5.2, dtype=float16) ==torch.tensor(836., dtype=torch.float16). this can lead iou to be larger than 1
and in cls loss, yolox multiplies target with iou, so that the bce loss can be negtive!

change iou calculation to float32 seems to fix that
@CLAassistant
Copy link

CLAassistant commented Jan 13, 2023

CLA assistant check
All committers have signed the CLA.

fix line length 103 > 100
@FateScript
Copy link
Member

Thanks for pointing it out. Another way to solve this issue is using clip to ensure the iou value. Why not using it? @h-bo

@h-bo
Copy link
Author

h-bo commented Feb 2, 2023

Thanks for pointing it out. Another way to solve this issue is using clip to ensure the iou value. Why not using it? @h-bo

That's also a solution, I'm not sure which one is better. I just tried float32 in my dataset and it improves 2%~

@Joker316701882
Copy link
Member

@h-bo Thanks! We will try it on COCO and see what happens.

@Joker316701882
Copy link
Member

@h-bo Hi. We have tested this PR on COCO. Here are our reproduced results:
Before -> After
Small: 40.7->40.3
Medium: 46.9 -> 47.0
Large: 49.3 -> 49.3

Seems this PR does not affect the result on COCO. We recommend using ''value clip'' to tackle your reported issue. What do you think?

@h-bo
Copy link
Author

h-bo commented Feb 6, 2023

@Joker316701882 It will be fine. Maybe the negtive cls loss problem is more severe in my dataset, if have time, I will dive into the reason.
By the way, did you find the negative cls loss occurrence on coco?

@Joker316701882
Copy link
Member

@h-bo
I did not check this very carefully, but the results can tell that it is not a severe issue on COCO. Welcome to report your updated understanding of this issue!

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.

4 participants