Open HamzaAzzaoui opened 6 years ago
I guess both ways are possible. If you wanna input multiple json files, you have to edit the loading functions. The second way, without have to change the loading functions, you will have to put all the required info in 1 json file as I mentioned in https://github.com/matterport/Mask_RCNN/issues/297 .
Thanks for the response, by loading functions , do you mean load_image and load_mask. I am using matterport implementation of maskRcnn. This is on example of my json files.
{ "image_filename": "Jan_11_2016_11_31_01_00.jpg", "complete": null, "labels": [ { "label_type": "polygon", "label_class": "rail", "vertices": [ { "x": 888.013771478238, "y": 1194.408468291834 }, { "x": 940.8538958081015, "y": 916.4233962715687 }, { "x": 995.9914168479589, "y": 688.9811219821563 }, { "x": 1030.45236749787, "y": 597.0852535823938 }, { "x": 1058.0211280177987, "y": 541.9477325425362 }, { "x": 1071.805508277763, "y": 518.9737654425955 }, { "x": 1085.5898885377276, "y": 521.2711621525897 }, { "x": 1067.210714857775, "y": 551.1373193825125 }, { "x": 1039.6419543378463, "y": 613.1670305523522 }, { "x": 1012.0731938179174, "y": 688.9811219821563 }, { "x": 975.3148464580124, "y": 842.9067015517586 }, { "x": 917.8799287081608, "y": 1194.408468291834 } ], "object_id": 1 }, { "label_type": "polygon", "label_class": "rail", "vertices": [ { "x": 1253.2998483672943, "y": 1194.408468291834 }, { "x": 1179.7831536474841, "y": 893.449429171628 }, { "x": 1152.2143931275552, "y": 769.3900068319485 }, { "x": 1133.8352194476029, "y": 656.8175680422394 }, { "x": 1131.5378227376088, "y": 615.4644272623462 }, { "x": 1131.5378227376088, "y": 564.9216996424768 }, { "x": 1136.1326161575969, "y": 521.2711621525897 }, { "x": 1145.3222029975732, "y": 523.5685588625837 }, { "x": 1143.0248062875792, "y": 587.8956667424175 }, { "x": 1143.0248062875792, "y": 647.6279812022632 }, { "x": 1198.1623273274367, "y": 900.3416193016102 }, { "x": 1278.571212177229, "y": 1199.003261711822 } ], "object_id": 2 }, { "label_type": "polygon", "label_class": "rail", "vertices": [ { "x": 1914.9501008455848, "y": 826.8249245818001 }, { "x": 1756.4297278559943, "y": 737.2264528920316 }, { "x": 1664.5338594562318, "y": 691.2785186921503 }, { "x": 1545.0692305365403, "y": 626.9514108123166 }, { "x": 1485.3369160766947, "y": 597.0852535823938 }, { "x": 1395.7384443869262, "y": 551.1373193825125 }, { "x": 1349.790510187045, "y": 525.8659555725777 }, { "x": 1361.2774937370152, "y": 516.6763687326015 }, { "x": 1538.1770404065583, "y": 606.27484042237 }, { "x": 1728.8609673360654, "y": 707.3602956621088 }, { "x": 1914.9501008455848, "y": 801.5535607718655 } ], "object_id": 3
}
] }
I would greatly appreciate any help
@HamzaAzzaoui you can check the coco.py
and then edit it. Hard to say which functions need or not to be edited but you can run the demo scripts and get an idea about how does this script work. You may put all your annotations together. What I saw in your json file is only the segmentation info but you will need to provide more info about the image when creating the final json file.
I managed to solve it, I wrote a script to convert all my json files to one json file that follows approximately the format of coco and modifier load_mask. Thanks again for your help.
@HamzaAzzaoui: please share the script that you wrote to join all .json files to one that quite close to the format of coco, I am stuck at this stage as well.
@AliceDinh , the script will depend on your source json files. I will upload my code to my github. If it doesn't help that much feel free to add a comment here with a sample json file you have.
@HamzaAzzaoui: My sample json file: { "shapes": [ { "label": "5", "line_color": null, "fill_color": null, "points": [ [ 63.23076923076919, 214.0887573964497 ], [ 63.23076923076919, 256.0887573964497 ], [ 90.23076923076918, 257.0887573964497 ], [ 90.23076923076918, 214.0887573964497 ] ] }, { "label": "2", "line_color": null, "fill_color": null, "points": [ [ 91.23076923076918, 215.0887573964497 ], [ 91.23076923076918, 259.0887573964497 ], [ 116.23076923076918, 261.0887573964497 ], [ 117.23076923076918, 214.0887573964497 ] ] } ], "lineColor": [ 0, 255, 0, 128 ], "fillColor": [ 255, 0, 0, 128 ], "imagePath": "C:/Users/Alice/Desktop/Newfolder/Access.jpg", }
@HamzaAzzaoui so the converter is already on your github right? @AliceDinh did you try it?
@fastlater Like I said, the converter works exactly for my data set but it's very to change that a little bit depending on needs.
@AliceDinh
Let me know if you need anything else.
@HamzaAzzaoui yeap I followed yours and modified to fit my files, it's okies now, thanks for your help. I modified a bit coco.py to load my annotation file, my images. Then I run the command: python number.py train --dataset=D:\DATA\Number-dataset --model=number There is an error I paste here, hope you can help:
Loading weights C:\Users\Alice\Mask_RCNN\mask_rcnn_coco.h5
Traceback (most recent call last):
File "C:\Users\Alice\Anaconda3\envs\MaskRCNN\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 686, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "C:\Users\Alice\Anaconda3\envs\MaskRCNN\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 516, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 44 and 324. Shapes are [1024,44] and [1024,324]. for 'Assign_682' (op: 'Assign') with input shapes: [1024,44], [1024,324].
Is that because I load coco weight that not fit my data? Or another reason you reckon? @fastlater: That suit his data, not mine, so you have to modify a bit
@AliceDinh Try runnin it with the imageNet weights and let me know how it goes.
@HamzaAzzaoui
I solved that error: it is because of calling wrong model.
I should:
python coco.py train --dataset=D:\DATA\Number-dataset --model=coco
OR:
python coco.py train --dataset=D:\DATA\Number-dataset --model=imagenet
what I did that was wrong:
python numpy.py train --dataset=D:\DATA\Number-dataset --model=numpy
@HamzaAzzaoui: Training raised below error:
ERROR:root:Error processing image {'id': 4, 'source': 'coco', 'path': 'D:\\DATA\\Number-dataset/val2018\\NUM_14.jpg', 'width': '416', 'height': '660', 'annotations': [{'id': 4, 'image_id': 4, 'iscrowd': 0, 'category_id': 3, 'segmentation': [[535, 360, 535, 414, 567, 414, 567, 360]], 'area': 1728.0, 'bbox': [535, 360, 567, 414]}]}
Traceback (most recent call last):
File "C:\Users\Alice\Mask_RCNN\model.py", line 1632, in data_generator
use_mini_mask=config.USE_MINI_MASK)
File "C:\Users\Alice\Mask_RCNN\model.py", line 1191, in load_image_gt
mask, class_ids = dataset.load_mask(image_id)
File "coco.py", line 244, in load_mask
image_info["width"])
File "coco.py", line 303, in annToMask
rle = self.annToRLE(ann, height, width)
File "coco.py", line 288, in annToRLE
rles = maskUtils.frPyObjects(segm, height, width)
File "pycocotools\_mask.pyx", line 295, in pycocotools._mask.frPyObjects
File "pycocotools\_mask.pyx", line 260, in pycocotools._mask.frPoly
TypeError: an integer is required
Once again, my data is not formatting properly, do you think so? Have you trained successfully with your data, please advise me the way you organize your data, I did organize exactly the same as coco but seem there is something that I haven't understood
@AliceDinh Sorry for the late response, I have been very busy lately. It looks to me that your height/width are not integers. Try adding a cast to your height and width values and let me know how it goes.
@HamzaAzzaoui: I managed to solve problems, thanks
Sorry, I know the issue is closed, but why not using a json editor like jq to merge the json files? something like jq for example: jq -s :[.[][]]" *.json > output.json (similar to this https://stackoverflow.com/questions/52547351/combine-all-json-files-in-a-directory-into-one-file-windows)
Hi, I'm using UEA computer vision image labeling tool to label some images, and it outputs a json file for each image. I changed the load_mask function so that it takes into consideration the format of my json file but I reliased that Mask Rcnn only takes one Annotation file ( json file ) for training. Is there anyway I can input multiple json files ( one for each image) in training or convert my json files to one json file. Thanks in advance