You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Binary Confusion Matrix does not work if target is float (even if all values are 0 or 1).
Note: It could be argued that target should always be int. However given that #146 was solved, I assume you will also want to solve this one, or at least include an error for it.
In my case, target was float because my csv was automatically loaded by pandas.
Traceback (most recent call last):
File "/mnt/c/Users/rafae/Documents/faculdade/thesis/thesis-framework/temp.py", line 12, in <module>
cm.update(input, target.to(torch.float32)) # error here^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/c/Users/rafae/Documents/faculdade/thesis/thesis-framework/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_contextreturn func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/mnt/c/Users/rafae/Documents/faculdade/thesis/thesis-framework/.venv/lib/python3.12/site-packages/torcheval/metrics/classification/confusion_matrix.py", line 311, in updateself.confusion_matrix += _binary_confusion_matrix_update(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/c/Users/rafae/Documents/faculdade/thesis/thesis-framework/.venv/lib/python3.12/site-packages/torcheval/metrics/functional/classification/confusion_matrix.py", line 175, in _binary_confusion_matrix_updatereturn _update(input, target, 2)
^^^^^^^^^^^^^^^^^^^^^^^^^RuntimeError: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
File "/mnt/c/Users/rafae/Documents/faculdade/thesis/thesis-framework/.venv/lib/python3.12/site-packages/torcheval/metrics/functional/classification/confusion_matrix.py", line 232, in _update# Each prediction creates an entry at the position (true, pred)
sparse_cm = torch.sparse_coo_tensor(coordinates, torch.ones_like(target), cm_shape)
~~~~~~~~~~~~~~~~~~~~~~~<---HEREreturn sparse_cm.to_dense()
RuntimeError: indices must be an int64 tensor
Interpretation
The coordinates tensor (corresponding to the indices parameter of sparse_coo_tensor) is a vstack of input (after applying the threshold, therefore an int tensor) with target. Since target is float, vstack must create the stacked tensor as float.
Versions
Versions
torcheval 0.0.7
torch 2.5.0
The text was updated successfully, but these errors were encountered:
🐛 Describe the bug
Binary Confusion Matrix does not work if
target
is float (even if all values are 0 or 1).Note: It could be argued that target should always be int. However given that #146 was solved, I assume you will also want to solve this one, or at least include an error for it.
In my case, target was float because my csv was automatically loaded by pandas.
Minimal example:
Error and Traceback
Interpretation
The
coordinates
tensor (corresponding to the indices parameter ofsparse_coo_tensor
) is avstack
ofinput
(after applying the threshold, therefore an int tensor) with target. Since target isfloat
,vstack
must create the stacked tensor as float.Versions
Versions
torcheval
0.0.7torch
2.5.0The text was updated successfully, but these errors were encountered: