ryouchinsa / Rectlabel-support

RectLabel is an offline image annotation tool for object detection and segmentation.
https://rectlabel.com
504 stars 73 forks source link

Conversion of annotations from COCO-annotator to yolov8 format #251

Closed deolipankaj closed 5 months ago

deolipankaj commented 5 months ago

Hi Ryo, i am trying to convert a dataset (https://github.com/norlab-ulaval/PercepTreeV1/tree/main) which has been labelled originally with the help of coco-annotator (https://github.com/jsbroks/coco-annotator) to the yolov8 format to be used for object detection/instance segmentation.

For conversion, i am using your updated "general_json2yolo" file which also has support for Keypoints. But while conversion, i am getting some issues with Keypoints.
If we look at a snippet of the coco json file, we have something that looks like this (wrt keypoints).. image

However, after also conversion, the yolov8 file looks like this image

Please ignore the class id, i rectified it. But can you please suggest why the keypoints are not getting normalized (between 0 and 1). I did not changed anything from the code. Also, i put use_segment and use_keypoint to true, but still there are no segmentation points in the converted yolov8 txt file.

And i guess, when I am doing the training for Yolov8, the error I am getting is due to this ? image

ryouchinsa commented 5 months ago

Thanks for writing the issue and introducing the dataset. We download the CanaTree100 and converted to segmentation and keypoints to YOLO format separately. On RectLabel, segmentations and keypoints are correctly shown.

スクリーンショット 2024-03-09 0 39 23

スクリーンショット 2024-03-09 0 26 18

To fix the class index -1 problem, change this line not to subtract 1 from the category_id. Usually in the COCO format, category_id starts from 1, but in this dataset, category_id starts from 0.

# cls = coco80[ann['category_id'] - 1] if cls91to80 else ann['category_id'] - 1  # class
cls = coco80[ann['category_id'] - 1] if cls91to80 else ann['category_id']  # class

In my understanding, when traing YOLOv8, segmentation and keypoints are trained separately. In Detectron, training from COCO format directly, it can train the segmentation and keypoints at the same time.

In the YOLO format for keypoints, (x, y, v) values are included, and a visibility flag v defined as v=0: not labeled, v=1: labeled but not visible, and v=2: labeled and visible.

Please let us know your feedback.

ryouchinsa commented 5 months ago

We updated the general_json2yolo script so that both segmentation and keypoints are converted in different lines.

convert_coco_json('../datasets/coco/annotations',  # directory with *.json
                          use_segments=True,
                          use_keypoints=True,
                          cls91to80=False,
                          category_id_starts_from_0=True)

スクリーンショット 2024-03-09 1 42 39

deolipankaj commented 5 months ago

Hi Ryo, thank you for the fast reply. I did try with the updated conversion file and here's what I encountered with.

  1. With the CanaTree100 dataset, everything works. Therefore, i can get the bounding boxes and segmentation maps.
  2. But whenever I am trying with the SynthTree43k dataset (train_rgb.json, val_rgb.json and test_rgb.json from here https://ulavaldti-my.sharepoint.com/personal/vigro7_ulaval_ca/_layouts/15/onedrive.aspx?id=%2Fpersonal%2Fvigro7%5Fulaval%5Fca%2FDocuments%2FDatasets%2FSynthTree43k%5FRGB&ga=1), the segmentation maps are giving me an error.
  3. If i only do the bounding box (i.e. use_segments=False, use_keypoints=False, cls91to80=False, category_id_starts_from_0=True), everything works fine.
  4. But if I do use_segments=True, use_keypoints=False, cls91to80=False, category_id_starts_from_0=True), I get the following error

image

  1. For simplicity, i have attached the files test_RGB.json val_RGB.json

Thanks..

ryouchinsa commented 5 months ago

Thanks for the detailed feedback.

We updated the general_json2yolo script so that it works for the SynthTree43k datasets.

Please let us know your feedback.

convert_coco_json('../datasets/coco/annotations',  # directory with *.json
                          use_segments=True,
                          use_keypoints=True,
                          rle_to_polygons_holes=False,
                          save_rle_masks=False,
                          cls91to80=False,
                          category_id_starts_from_0=True)

スクリーンショット 2024-03-21 8 14 23

deolipankaj commented 5 months ago

Hi Ryo,

Thank you for your support. Now the code is working perfectly for all use-cases.

ryouchinsa commented 5 months ago

Thanks for your detailed feedback. If you have any other problems, please let us know. We are happy to support users.