How do I match an annotations.json file with their respective images from an image folder?

77 ビュー (過去 30 日間)
I downloaded the TACO trash detection dataset with annotations.json file. I am trying to train a mask r-cnn to perform image segmenation on images to identify and locate litter in images. Does anyone know how to unpack the annotations so that I can begin training the network?
I have been following this document which does what I want but with a COCO dataset. https://uk.mathworks.com/help/deeplearning/ug/instance-segmentation-using-mask-rcnn.html
The image dataset and annotations.json file are available for download through this link: https://www.kaggle.com/kneroma/tacotrashdataset?select=data . The file is too large to post here.
  2 件のコメント
Eoghan Mckay
Eoghan Mckay 2022 年 3 月 3 日
The annotation file is available in through the link. IIt will not post here because .json is not supported.

サインインしてコメントする。

回答 (1 件)

Ive J
Ive J 2022 年 3 月 3 日
Try this
js = jsondecode(fileread("annotations.json.txt")) % file extension was changed only for upload
js = struct with fields:
info: [1×1 struct] images: {1500×1 cell} annotations: [4784×1 struct] scene_annotations: [4296×1 struct] licenses: [] categories: [60×1 struct] scene_categories: [7×1 struct]
% get info of first image
js.images{1}
ans = struct with fields:
id: 0 width: 1537 height: 2049 file_name: 'batch_1/000006.jpg' license: [] flickr_url: 'https://farm66.staticflickr.com/65535/33978196618_e30a59e0a8_o.png' coco_url: [] date_captured: [] flickr_640_url: 'https://farm66.staticflickr.com/65535/33978196618_632623b4fc_z.jpg'
  1 件のコメント
Eoghan Mckay
Eoghan Mckay 2022 年 3 月 7 日
This gives infomation on the individual images but my goal is to apply the bounding boxes, segmentation to each image. I want to do this:
Extract the COCO annotations to MAT files using the unpackAnnotations helper function, which is attached to this example as a supporting file in the folder helper. Each MAT file corresponds to a single training image and contains the file name, bounding boxes, instance labels, and instance masks for each training image. The function converts object instances specified as polygon coordinates to binary masks using the poly2mask (Image Processing Toolbox) function.
Without this helper function that does not work.
helper.unpackAnnotations(trainClassNames,annotationFile,imageFolder,unpackAnnotationDir);
With MAT files I can creaste a datastore that I can then train with the below however I ma unsure whether the cocoAnnotationMATReader will work.
ds = fileDatastore(unpackAnnotationDir, ...
'ReadFcn',@(x)helper.cocoAnnotationMATReader(x,imageFolder));

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by