mmpose
                                
                                
                                
                                    mmpose copied to clipboard
                            
                            
                            
                        [Bug] Iterable bug in CocoMetric/results2json.py
Prerequisite
- [X] I have searched Issues and Discussions but cannot get the expected help.
 - [X] The bug has not been fixed in the latest version(https://github.com/open-mmlab/mmpose).
 
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]