chrise96 / image-to-coco-json-converter

Convert segmentation RGB mask images to COCO JSON format
199 stars 57 forks source link

Error When running script AttributeError: 'Image' object has no attribute 'shape' #2

Closed Mrgove10 closed 3 years ago

Mrgove10 commented 3 years ago

Hello, I have clones the repo and done absolutly 0 modification. When running your notebook i get AttributeError: 'Image' object has no attribute 'shape'. More details :

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-77e827a19691> in <module>
     67     for keyword in ['train', 'val']:
     68         mask_path = 'dataset/{}_mask'.format(keyword)
---> 69         coco_format['images'], coco_format['annotations'] = images_annotations_info(mask_path)
     70         #print(json.dumps(coco_format))
     71         with open('output/{}.json'.format(keyword),'w') as outfile:

<ipython-input-2-77e827a19691> in images_annotations_info(maskpath)
     41 
     42             # 'annotations' info
---> 43             polygons, segmentations = create_sub_mask_annotation(sub_mask)
     44 
     45             # Three labels are multipolygons in our case: wall, roof and sky

D:\PERSO\PERSONAL WORK\15 - AI MachineLearning\image-to-coco-json-converter\create_annotations.py in create_sub_mask_annotation(sub_mask)
     35     # Note: there could be multiple contours if the object
     36     # is partially occluded. (E.g. an elephant behind a tree)
---> 37     contours = measure.find_contours(sub_mask, 0.5, positive_orientation='low')
     38 
     39     polygons = []

c:\users\richa\appdata\local\programs\python\python37\lib\site-packages\skimage\measure\_find_contours.py in find_contours(array, level, fully_connected, positive_orientation, mask)
    121         raise ValueError('Parameters "positive_orientation" must be either '
    122                          '"high" or "low".')
--> 123     if array.shape[0] < 2 or array.shape[1] < 2:
    124         raise ValueError("Input array must be at least 2x2.")
    125     if array.ndim != 2:

AttributeError: 'Image' object has no attribute 'shape'

Pip versions : Pillow 8.0.1 numpy 1.18.5 scikit-image 0.17.2 Shapely 1.7.1

Mabey this is linked to a different version of a library ?

Thanks in advance

Mrgove10 commented 3 years ago

Found a fix, will make a PR

chrise96 commented 3 years ago

A different version of a library indeed seems the issue... I got the same error today after updating all libraries. I refactored the code, along with your changes, and merged it to the master 👍 Thank you!