-
Notifications
You must be signed in to change notification settings - Fork 751
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] fix np.arange() output not stable error #1749
base: dev-1.x
Are you sure you want to change the base?
[Fix] fix np.arange() output not stable error #1749
Conversation
但个人感觉以这种方式解决问题self.pred_score_thrs获取值得代码没有之前的优雅 |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## dev-1.x #1749 +/- ##
===========================================
- Coverage 89.18% 88.08% -1.10%
===========================================
Files 193 176 -17
Lines 11316 11022 -294
Branches 1608 1558 -50
===========================================
- Hits 10092 9709 -383
- Misses 903 1022 +119
+ Partials 321 291 -30
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 53 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR also changes the definition of stop
a bit by excluding it from the range, but I don't think it's a good idea.
- Breaking backward compatibility without sufficient reasons is not encouraged, since users might get a different result with the same config. And for now I don't see outstanding reasons for this change.
- If we apply this change, we have to manually shift the stop point a bit if we want to filter the results with the original ending threshold. This becomes weirder when we want the threshold to stop at 1.
Therefore, it's better to roll back this definition change and stick to the old behavior.
int( | ||
np.round((pred_score_thrs['stop'] - pred_score_thrs['start']) / | ||
pred_score_thrs['step'])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about int((pred_score_thrs['stop'] - pred_score_thrs['start']) // pred_score_thrs['step'])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still can not include "stop" when using "start=0.3, stop=0.9, step=0.1".
Using np.linspace(start, stop, int(np.round((stop - start) / step)) + 1, endpoint=True)
can fix it.
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
mmocr中pred_score_thrs生成的范围需要包含stop值,然而使用np.arange可能会因为浮点型数值精度问题导致不包含stop值。
https://numpy.org/doc/stable/reference/generated/numpy.arange.html
numpy官方也提示了这个潜在的问题是因为函数内部实现导致,并且建议如果要使用non-integer step最好还是使用numpy.linspace().
Modification
使用
np.linspace(start, stop, int(np.round((stop - start) / step)) + 1, endpoint=True)
替换np.arange(start, stop, step)
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist
Before PR:
After PR: