Repository navigation
Fix recall metrics with integer-valued floating labels - #233
Open
laasyapriya2007 wants to merge 1 commit into
Open
laasyapriya2007 wants to merge 1 commit into
laasyapriya2007 wants to merge 1 commit into
Conversation
Summary: In `BinaryRecall`, computing true positives via bitwise AND `(input & target).sum()` raises `RuntimeError: "bitwise_and_cpu" not implemented for 'Float'` when integer-valued floating-point targets (such as `torch.tensor([1.0, 0.0])`) are passed. In `MulticlassRecall`, floating targets reach scatter indexing and raise `RuntimeError: scatter(): Expected dtype int32/int64 for index`. Use multiplication `(input * target).sum()` for `BinaryRecall` (consistent with `BinaryPrecision` and `BinaryF1Score`), and ensure targets and inputs are converted to `torch.int64` before scatter accumulation in `MulticlassRecall`. Add unit tests covering float32 and float64 targets across both functional and class-based recall implementations (with state merging and all averaging modes). Fixes meta-pytorch#209
This branch has not been deployed
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.
Please read through our contribution guide prior to creating your pull request.
Summary:
In
BinaryRecall, computing true positives via bitwise AND(input & target).sum()raisesRuntimeError: "bitwise_and_cpu" not implemented for 'Float'when integer-valued floating-point targets (such astorch.tensor([1.0, 0.0])) are passed. InMulticlassRecall, floating targets reach scatter indexing and raiseRuntimeError: scatter(): Expected dtype int32/int64 for index.This PR:
(input * target).sum()in_binary_recall_update(consistent withBinaryPrecisionandBinaryF1Score).torch.int64before scatter accumulation in_recall_update.torch.float32andtorch.float64targets across both functional and class-based recall implementations (including multi-batch state merging and all averaging modes: None, micro, macro, weighted).Test plan:
pytest tests/metrics/functional/classification/test_recall.py(11 passed).pytest tests/metrics/classification/test_recall.py -k float_target(all passed).pre-commit run --files torcheval/metrics/functional/classification/recall.py tests/metrics/classification/test_recall.py tests/metrics/functional/classification/test_recall.py(all hooks passed: trailing whitespace, flake8, ufmt).Fixes #209