-
Notifications
You must be signed in to change notification settings - Fork 411
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 metrics in macro average #303
Conversation
Hey @SkafteNicki changing the weights to account for missing classes seems to fix the accuracy, and precision but not f1 score. Have a look at the following snippet. import torch
import torchmetrics
from sklearn.metrics import f1_score, accuracy_score, precision_score
y_pred = y_true = torch.tensor([1, 6, 6, 6, 3, 6, 3, 6, 6, 3, 6, 3, 6, 6, 3, 6, 3, 3, 6, 6, 6, 6, 6, 6,
6, 3, 5, 6, 6, 3, 6, 6, 6, 6, 3, 6, 6, 3, 3, 1, 3, 1, 6, 3, 3, 1, 3, 6,
4, 6, 6, 6, 6, 6, 6, 3, 3, 6, 3, 6, 1, 0, 5, 3, 6, 6, 6, 6, 3, 0, 6, 3,
3, 3, 6, 3, 4]) # no class with id=2 !
print(f'Metrics:')
print(f'F1: {f1_score(y_true.numpy().astype(int).tolist(), y_pred.numpy().astype(int).tolist(), average="macro")}')
print(f'ACC: {accuracy_score(y_true.numpy().astype(int).tolist(), y_pred.numpy().astype(int).tolist())}')
print(f'PREC: {precision_score(y_true.numpy().astype(int).tolist(), y_pred.numpy().astype(int).tolist(), average="macro")}')
print(f'TM F1: {torchmetrics.functional.f1(y_pred, y_true, average="macro", num_classes=7)}')
print(f'TM acc: {torchmetrics.functional.accuracy(y_pred, y_true, average="macro", num_classes=7)}')
print(f'TM prec: {torchmetrics.functional.precision(y_pred, y_true, average="macro", num_classes=7)}')
I would look into the f1 score issue tomorrow. I guess we should test this. |
Hi @vatch123, |
Codecov Report
@@ Coverage Diff @@
## master #303 +/- ##
==========================================
+ Coverage 96.11% 96.12% +0.01%
==========================================
Files 124 124
Lines 3986 4002 +16
==========================================
+ Hits 3831 3847 +16
Misses 155 155
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Yes doing that seems to fix it. Although some other tests do fail. |
@SkafteNicki @vatch123 how is it going here? :] |
Hey sorry was a bit busy this weekend. However, removing the line with @SkafteNicki suggested breaks the accuracy tests. So something odd is happening which I wasn't able to figure out then. Let me have a look again |
Hey, @SkafteNicki I was probing the issue. On local testing this particular test fails
Seems like the calculated accuracy is getting rounded off somewhere. But the trace shows one more |
As another comment, can you please also add the test case you used to find the issue to the tests to avoid regressions in the future? For test suit being slow - you should be able to run just individual test files in pytest while you are debugging a particular test to avoid waiting for everything to run. |
Hey @SkafteNicki, I am a little stuck here. I can't figure out which inputs are breaking the tests on F1. The tests don't run locally completely throwing this error - |
@SkafteNicki @vatch123 any chance we get for tomorrow bugfix release? |
Hi, Sorry for the late reply I am little stuck here and actually unable to figure what is actually breaking. I guess I would need some more inputs on this.
|
@vatch123 how is it going here? 🐰 |
Hey. Sorry been busy recently did not get a chance to probe deeper. I tried with a debugger but haven't been able to pinpoint the error. Will need some time and help on this I guess. |
for more information, see https://pre-commit.ci
Hey @SkafteNicki. Thanks for the help here. Can you let me know what was the actual issue? I see you mentioned |
Yes @SkafteNicki @Borda Can someone please explain whether or not thins works for dist_sync_on_step. During testing I am getting a macro accuracy value of 0.1996 when it should be about 0.65. I calculated manually after testing by extracting all the data to a csv. |
Before submitting
What does this PR do?
Fixes #295 and Fixes #300.
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃