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

[Bug] Iterable bug in CocoMetric/results2json.py #3143

Open
2 tasks done
simonlsp opened this issue Oct 24, 2024 · 0 comments
Open
2 tasks done

[Bug] Iterable bug in CocoMetric/results2json.py #3143

simonlsp opened this issue Oct 24, 2024 · 0 comments

Comments

@simonlsp
Copy link

simonlsp commented Oct 24, 2024

Prerequisite

Environment

This bug is not related to the environment.

Reproduces the problem - code sample

This bug is not related to specific code.

Reproduces the problem - command or script

This bug is not related to specific command.

Reproduces the problem - error message

IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed

Additional information

In mmpose\evaluation\metrics\coco_metric.py, line 536-537

if isinstance(img_kpt['category_id'], Iterable):
    img_kpt['category_id'] = img_kpt['category_id'][0]

0-dimensional numpy array with single digit IS an "Iterable" instance, but it IS NOT Iterable
So, when there is only one category_id, it raises

IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed

Changing "[0]" to ".iter()" won't help, as 0-dimensional array is not iterable, though it is an iterable instance.

TypeError: iteration over a 0-d array

So, we need to change this script to something like this:

if isinstance(img_kpt['category_id'], Iterable):
    if isinstance(img_kpt['category_id'], np.ndarray):
        if len(img_kpt['category_id'].shape) == 0:
            img_kpt['category_id'] = int(img_kpt['category_id'])
        else:
            img_kpt['category_id'] = img_kpt['category_id'].flatten()[0]
    else:
        img_kpt['category_id'] = img_kpt['category_id'][0]
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