matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.52k stars 11.68k forks source link

How can i train mask-r-cnn model with different annotations structure? #2542

Open dariodellamura opened 3 years ago

dariodellamura commented 3 years ago

Hi guys, I'm a data science student and I'm trying to build a mask-r-cnn model.

The annotations have been provided to me with this excel structure: Name, Class, Polygon coordinates, Region_count (nth polygon in the same image).

I've converted this xlsx to csv to json. This is the json output: [ { "Name": "foto_1jpg.jpg", "Class": "tennis", "Region_count": "1", "Polygon Cordinates": "\"all_points_x\":[154,157,230,275,278,218,160,112,113,154],\"all_points_y\":[461,461,455,495,576,625,625,563,505,463]" }, { "Name": "foto_1jpg.jpg", "Class": "soccer", "Region_count": "2", "Polygon Cordinates": "\"all_points_x\":[446,557,685,795,826,815,738,628,505,422,346,331,354,443],\"all_points_y\":[230,186,212,321,411,538,641,687,684,632,525,426,331,224]" }, { "Name": "foto_2jpg.jpg", "Class": "soccer", "Region_count": "1", "Polygon Cordinates": "all_points_x:[331,403,518,626,688,734,758,681,594,484,369,314,282,274,329],\"all_points_y\":[399,340,316,342,380,463,607,736,787,796,745,683,592,503,405]" }]

After this I've tried to train mask-r-cnn with this json, but my tries are failed.

How can I adapt my json file to a VIA json file structure ?Or it is better to adapt the python code to my json format ? Thanks for the attention.

dariodellamura commented 3 years ago

EDIT:

I used a code to make json annotation look like VIA tool annotation, the output is: { "filename": "picture_1.jpg", "Region_count": "1", "region": [ { "shape_attributes": { "name": "polygon", "Coordinates": "\"all_points_x\":[1700,2743,2746, 454, 77],\"all_points_y\":[6,1376,3, 22, 352]" }, "region_attribute": { "name": "tennis" } } ] }, { "filename": "picture_1.jpg", "Region_count": "2", "region": [ { "shape_attributes": { "name": "polygon", "Coordinates": "\"all_points_x\":[0,70,890,193,3,44],\"all_points_y\":[3,6,1547,1547,1067, 87]" }, "region_attribute": { "name": "soccer" } } ] } ]

Customization function "def load_custom"

` annotations1 = json.load(open(os.path.join(dataset_dir, "set_labelling.json"))) new_dict = {}

for item in annotations1: name = item['filename'], item['Layer'] new_dict[name] = item annotations = list(new_dict.values()) # don't need the dict key for a in annotations: polygons = [r['shape_attributes']['Coordinates'] for r in a['region']] objects = [s['region_attribute']['name'] for s in a['region']] `

ERROR: string indices must be integers on : rr, cc = skimage.draw.polygon(p['all_points_y'], p['all_points_x'])