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

46 ビュー (過去 30 日間)
Eoghan Mckay
Eoghan Mckay 2022 年 2 月 28 日
コメント済み: Eoghan Mckay 2022 年 3 月 7 日
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.
The image dataset and annotations.json file are available for download through this link: . The file is too large to post here.
  2 件のコメント
Mahesh Taparia
Mahesh Taparia 2022 年 3 月 3 日
Can you share a sample annotation file? It will be helpful.
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
ans = struct with fields:
id: 0 width: 1537 height: 2049 file_name: 'batch_1/000006.jpg' license: [] flickr_url: '' coco_url: [] date_captured: [] flickr_640_url: ''
  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.
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, ...


Community Treasure Hunt

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

Start Hunting!

Translated by