Add label-wise accuracy support for multilabel Accuracy metric - #3820
Open
danijimmy19 wants to merge 1 commit into
Open
Add label-wise accuracy support for multilabel Accuracy metric#3820danijimmy19 wants to merge 1 commit into
danijimmy19 wants to merge 1 commit into
Conversation
Author
|
Hi @vfdev-5, this is my first contribution to this project. I've implemented label-wise accuracy support for issue #513. While working on this, I noticed PR #3810 is also open against the same issue with a similar approach, happy to differentiate my implementation or defer to that PR, whichever you'd prefer. Would appreciate a review when you have time! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #513.
Accuracycurrently only supports subset accuracy (exact match across all labels) for multilabel classification — it collapses allClabels per sample withtorch.all(..., dim=-1). This hides which specific labels a model is getting wrong, unlikePrecision/Recall, which already support per-label output viaaverage=False.This PR adds an
average="label-wise"option toAccuracyforis_multilabel=True, returning a(C,)tensor of per-label accuracy instead of a single scalar.Root cause
Accuracy's_num_correctis a scalar with noaveragedispatch, unlike_BasePrecisionRecall, which was given tensor accumulators and dispatch whenPrecision/Recallwere added in the same commit multilabel support landed inAccuracy(1a8ead8b).Accuracywas never brought to parity.Change
In
update(), whenaverage="label-wise":compute()returns a(C,)tensor foraverage="label-wise", and preserves the existing scalar-float behavior otherwise.Example
Edge cases handled
average="label-wise"withis_multilabel=FalseraisesValueErrorin__init__(N, C, H, W)multilabel inputs are flattened to(N*H*W, C)before the per-label sum_num_correctof shape(C,)is handled correctly by the existing@sync_all_reducedecoratorcompute()before anyupdate()raisesNotComputableErrorvia the existing guardTesting
Added tests to
tests/ignite/metrics/test_accuracy.pycovering:(C,), all-correct/all-wrong casessklearn.metrics.accuracy_scorecomputed per columnaverage=None) unchangedaverage="label-wise"+is_multilabel=False)Check list