Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

fix: Only export bboxes and polygon segmentations to YOLO #196

Closed
wants to merge 2 commits into from

Conversation

frederik-ai
Copy link

Fix issue HumanSignal/label-studio#3556

Only allow specific types of annotations to be added to YOLO.
Otherwise metadata classes are added to classes.txt.

Both RectangleLabels and PolygonLabels are added, as YOLO export now also supports segmentation.
Additionally, it would break COCO exports to only allow RectangleLabels.

@github-actions github-actions bot added the fix label Feb 2, 2023
@makseq makseq changed the title fix: Only export bboxes and segmentations to YOLO fix: Only export bboxes and polygon segmentations to YOLO Feb 2, 2023
@@ -900,6 +900,10 @@ def _get_labels(self):
category_name_to_id = dict()

for name, info in self._schema.items():
# ignore labels that are not bounding boxes or segmentations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for a long review.

  1. We have to add rectangle and polygon too - https://labelstud.io/tags/rectangle.html
  2. _get_labels is used in COCO also, COCO supports another set of labels.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that there should be a different _get_labels procedure for YOLO and for COCO, right? Because they support different kinds of labels.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pass all supported types this way

_get_labels(types=['rectanglelabels', ...])

and used different calls in YOLO and COCO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question - if _get_labels returns nothing, will the image be included to export?

@@ -900,6 +900,10 @@ def _get_labels(self):
category_name_to_id = dict()

for name, info in self._schema.items():
# ignore labels that are not bounding boxes or segmentations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pass all supported types this way

_get_labels(types=['rectanglelabels', ...])

and used different calls in YOLO and COCO.

@@ -900,6 +900,10 @@ def _get_labels(self):
category_name_to_id = dict()

for name, info in self._schema.items():
# ignore labels that are not bounding boxes or segmentations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question - if _get_labels returns nothing, will the image be included to export?

@frederik-ai
Copy link
Author

Sorry for the late response, seems like I have the notifications disabled.

To your question: When exporting empty annotations, the images are still exported. So I assume that an empty return value of _get_labes still leads to an export.

I now changed it such that the label types are only filtered by 'rectangleLabels' and 'polygonLabels' for YOLO exports.

@luuzk
Copy link

luuzk commented Aug 8, 2023

Seems like all threads are solved. Can we merge?

luuzk
luuzk approved these changes Sep 12, 2023
@makseq
Copy link
Member

makseq commented Jun 4, 2024

Unfortunately, this fix doesn't work for this case:

<View>
  <Image name="image" value="$image"/>
  <Polygon name="poly" toName="image" />
  <Rectangle name="rect" toName="image" />
  <Labels name="label" toName="image">
    <Label value="Airplane" background="green"/>
    <Label value="Car" background="blue"/>
  </Labels>
</View>

Check out this annotations: for each rectangle and polygon we will have a region with labels, but without type:

{
  "id": 112360554,
  "data": {
    "image": "https://app.heartex.com/storage-data/uploaded/?filepath=upload/71582/013686d8-9-add-group.png"
  },
  "annotations": [
    {
      "id": 38247361,
      "created_username": " makseq@gmail.com, 9",
      "created_ago": "2 minutes",
      "completed_by": {
        "id": 9,
        "first_name": "",
        "last_name": "",
        "avatar": "https://app.heartex.com/storage-data/uploaded/?filepath=avatars/ff6c719c-430d1d9e-b209-4c54-b1e5-56c73229588c_clipped_rev_1.png",
        "email": "makseq@gmail.com",
        "initials": "ma"
      },
      "last_annotation_history": 40544406,
      "reviews": null,
      "result": [
        {
          "id": "26qBD9fhiy",
          "type": "rectangle",
          "value": {
            "x": 19.158878504672895,
            "y": 48.214285714285715,
            "width": 12.92834890965732,
            "height": 28.571428571428577,
            "rotation": 0
          },
          "origin": "manual",
          "to_name": "image",
          "from_name": "rect",
          "image_rotation": 0,
          "original_width": 1407,
          "original_height": 490
        },
        {
          "id": "26qBD9fhiy",
          "type": "labels",
          "value": {
            "x": 19.158878504672895,
            "y": 48.214285714285715,
            "width": 12.92834890965732,
            "height": 28.571428571428577,
            "labels": [
              "Airplane"
            ],
            "rotation": 0
          },
          "origin": "manual",
          "to_name": "image",
          "from_name": "label",
          "image_rotation": 0,
          "original_width": 1407,
          "original_height": 490
        },
        {
          "id": "trv0izsa9n",
          "type": "polygon",
          "value": {
            "closed": true,
            "points": [
              [
                47.50778816199377,
                72.32142857142857
              ],
              [
                61.37071651090342,
                62.94642857142857
              ],
              [
                58.09968847352025,
                36.607142857142854
              ],
              [
                49.22118380062305,
                43.30357142857143
              ]
            ]
          },
          "origin": "manual",
          "to_name": "image",
          "from_name": "poly",
          "image_rotation": 0,
          "original_width": 1407,
          "original_height": 490
        },
        {
          "id": "trv0izsa9n",
          "type": "labels",
          "value": {
            "closed": true,
            "labels": [
              "Car"
            ],
            "points": [
              [
                47.50778816199377,
                72.32142857142857
              ],
              [
                61.37071651090342,
                62.94642857142857
              ],
              [
                58.09968847352025,
                36.607142857142854
              ],
              [
                49.22118380062305,
                43.30357142857143
              ]
            ]
          },
          "origin": "manual",
          "to_name": "image",
          "from_name": "label",
          "image_rotation": 0,
          "original_width": 1407,
          "original_height": 490
        }
      ],
      "was_cancelled": false,
      "ground_truth": false,
      "created_at": "2024-06-04T14:57:03.805164Z",
      "updated_at": "2024-06-04T14:59:25.112811Z",
      "draft_created_at": "2024-06-04T14:56:59.142594Z",
      "lead_time": 151.28400000000002,
      "import_id": null,
      "last_action": "updated",
      "task": 112360554,
      "project": 71582,
      "updated_by": 9,
      "parent_prediction": null,
      "parent_annotation": null,
      "last_created_by": 9,
      "comment_count": 0,
      "unresolved_comment_count": 0
    }
  ],
  "predictions": []
}

@makseq
Copy link
Member

makseq commented Jun 4, 2024

After careful consideration, we’ve determined that this is more of an improvement than a critical bug. Additionally, it seems to be an outdated request and hasn’t garnered much interest from the community. For these reasons, we will be closing this issue. We will continue developing the converter library as a part of Label Studio SDK.

We appreciate your understanding and encourage you to submit your feedback, questions and suggestions here:
https://github.com/HumanSignal/label-studio-sdk/issues

@makseq makseq closed this Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants