-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Reformat iou [func] and add IoU class #4704
Conversation
Hello @deng-cy! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-01-08 12:59:07 UTC |
Codecov Report
@@ Coverage Diff @@
## release/1.2-dev #4704 +/- ##
===============================================
Coverage 93% 93%
===============================================
Files 148 150 +2
Lines 10480 10490 +10
===============================================
+ Hits 9709 9719 +10
Misses 771 771 |
iou
and add IoU
classThere 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.
Smaller comments for now.
For testing, you should be able to test against sklearns jaccard score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.jaccard_score.html as it computes the same metric
A problem with this implementation is that it will not work for multi-label inputs (since it is based on the confusion matrix) |
I did not know that. This implementation passed all tests. Can you give an example? |
It passed all tests because currently the tests are not really well done (not your fault, just the state of the testing library). What is done in these tests is that the vectors are unrolled (with As for an example: try this [edited to include average='macro']
This should give you 0.6666 (it's the example from sklearn documentation)
|
This problem isn't something you can easily fix, because the confusion matrix can not deal with multi-label inputs. You have to use a different approach - computing the number of true positives, false positives, etc. directly. I'm working on a PR for this :) |
The previous (current) implementation uses what you described, but I think our outputs are the same. The sk one treats each column as a class, and calculates accuracy of each class. I feel it can be substituted by accuracy? |
Your PR still uses the same "unrolling": please see the The outputs are not the same. I tried the example I gave you for your PR, and the results are (for reduction method):
None of them gives the correct result, which is 0.6666 Sklearn's jaccard_score does not calculate the accuracy of each class - it calculates the IoU of each class. There isn't even a definition for what an "accuracy" of a class should be :) The sklearn example is simple enough to do by hand, if you don't believe me. |
I meant my output was the same as the current implementation (which used your way and I deleted), not the sklearn function. The reason I felt it looked like accuracy is that
seems accuracy to me lol. I understand it may be different from accuracy (I have not dug into it), but I think it is a choice of what function we want here. At least from the current implementation, I do not think such Also, if you want to implement |
I checked and you are right that the current implementation also gets it wrong. You can check out sklearn's great used guide for a definition of IoU and accuracy. IoU is defined as tp / (tp + fp + fn). You do get equivalence between this and (tp + tn)/(tp + fp + tn + fn), which you could call "class accuracy", in a simple 2 sample case, but generally it is not true. I am not one of the code owners :) But in my opinon IoU should definetly support multi-label inputs And I don't think you can use any tricks to get multi-label data into any kind of meaningful confusion matrix representation. |
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.
still need to handle back-compatibility as shell linking the new function location
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.
I have not check the computation, but still, there are some minor thing for propper deprecation
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
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.
nice job!
What does this PR do?
This PR makes some changes related to iou:
iou
(functional) to be more flexible to input float value. The code is rewritten to use confusion matrix to get the score.IoU
class which functions the same as (new)iou
.I tested this class on my machine, but did not write a pytest file for
IoU
class.Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In in short, see following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃