Skip to content
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

ValueError: Predictions and/or references don't match the expected format. #563

Open
antopost opened this issue Mar 20, 2024 · 1 comment

Comments

@antopost
Copy link

Getting this error when trying to compute IoU using the Huggingface example.
Flattening arrays does not solve the problem as this issue suggests.

Steps to reproduce:

import numpy as np
import evaluate

mean_iou = evaluate.load("mean_iou")
predicted = np.array([[2, 2, 3], [8, 2, 4], [3, 255, 2]])
ground_truth = np.array([[1, 2, 2], [8, 2, 1], [3, 255, 1]])
results = mean_iou.compute(predictions=predicted, references=ground_truth, num_labels=10, ignore_index=255)

Using
evaluate 0.4.1
numpy 1.26.1

Full error:

Traceback (most recent call last):
  File "/home/anba/catkin_ws/src/tas_dev/dev/anba/SAM/test.py", line 7, in <module>
    results = mean_iou.compute(predictions=predicted, references=ground_truth, num_labels=10, ignore_index=255)
  File "/home/anba/anaconda3/envs/SAM/lib/python3.10/site-packages/evaluate/module.py", line 450, in compute
    self.add_batch(**inputs)
  File "/home/anba/anaconda3/envs/SAM/lib/python3.10/site-packages/evaluate/module.py", line 541, in add_batch
    raise ValueError(error_msg) from None
ValueError: Predictions and/or references don't match the expected format.
Expected format: {'predictions': Sequence(feature=Sequence(feature=Value(dtype='uint16', id=None), length=-1, id=None), length=-1, id=None), 'references': Sequence(feature=Sequence(feature=Value(dtype='uint16', id=None), length=-1, id=None), length=-1, id=None)},
Input predictions: [  2   2   3   8   2   4   3 255   2],
Input references: [  1   2   2   8   2   1   3 255   1]
@antopost
Copy link
Author

Fixed it. The error message does give some clues.
The np arrays must be uint16 and they must be passed within a list.
That being said, it doesn't really make sense to me why this would be the case.
The example code in the docs should work as well.

Here's the fixed example:

import numpy as np
import evaluate

mean_iou = evaluate.load("mean_iou")
predicted = np.array([[2, 2, 3], [8, 2, 4], [3, 255, 2]], dtype=np.uint16)
ground_truth = np.array([[1, 2, 2], [8, 2, 1], [3, 255, 1]], dtype=np.uint16)
results = mean_iou.compute(predictions=[predicted], references=[ground_truth], num_labels=10, ignore_index=255)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant