HumanSignal / label-studio

Label Studio is a multi-type data labeling and annotation tool with standardized output format
https://labelstud.io
Apache License 2.0
18.38k stars 2.31k forks source link

Export bbox and polygon labels only without other labels in YOLO classes.txt #3556

Open frederik-ai opened 1 year ago

frederik-ai commented 1 year ago

Is your feature request related to a problem? Please describe. I am currently labeling data for object detection. The data will be used to train a YOLOv5 net.

I would not only like to label each region with a class (e.g. plane or car), but to also add metadata to each region and to the whole image. The metadata should state additional information about the currently selected region (whether the plane/car is moving) and about the whole image (image quality).

However, I currently do not see a way of implementing this in a way so that YOLO classes.txt is not affected. I would like to add metadata so that Label Studio does not interpret its content as class labels.

Describe alternatives you've considered To add my metadata, I followed the approach in issue #2256. I implemented the metadata with Choices tags in the labeling configuration:

<View>
  <Image name="image" value="$image"/>
  <RectangleLabels name="label" toName="image">
    <Label value="Airplane" background="green"/>
    <Label value="Car" background="blue"/>
  </RectangleLabels>

  <Choices name="is_moving" toName="image" perRegion="true" required="true" choice="single-radio" showInline="true">
    <Header value="Is Moving" />
    <Choice value="yes "/>
    <Choice value="no "/>
  </Choices>

  <Choices name="img_quality" toName="image" perRegion="false" required="true" choice="single-radio" showInline="true">
    <Header value="Image Quality" />
    <Choice value="unknown "/>
    <Choice value="good" />
    <Choice value="ok" />
    <Choice value="bad" />
  </Choices>
</View>

When I export my annotations as JSON, everything is as intended. However, when I export to YOLO, the metadata classes (yes, no, unknown,...) are added to the classes.txt:

Airplane
Car
bad
good
no 
ok
unknown 
yes

However, it would make more sense for my use-case if the classes.txt contained only the two classes I actually want to detect:

Airplane
Car

I would only like the metadata to be shown when I export my tasks to JSON. The metadata is not relevant for my YOLO net.

Describe the solution you'd like If I am not missing a solution and there is actually no way of implementing this, I would like a way to add metadata without it being interpeted as class labels. Maybe by adding a specific XML attribute or tag.

luuzk commented 1 year ago

This breaks YOLO format since classes are added where no labels (bounding boxes) are ever provided. However, networks reading the export try to predict way too much classes (8 instead of 2 in the case of @frederikcpp).

makseq commented 1 year ago

I see the problem here. There should be done some filtering by RectagleLabels.

The fix will be something like this:

for name, info in self._schema.items():
            labels |= set(info['labels'])

=>

for name, info in self._schema.items():
    if info['type'].lower() != 'rectanglelabels':
        continue

    labels |= set(info['labels'])

If you could contribute and test this, it would be great!

frederik-ai commented 1 year ago

I see, thank you for the suggestion. I will test if this fix works and contribute it if it does.

luuzk commented 1 year ago

Any updates on this @frederikcpp? Would be great to integrate this fix into the next release.

frederik-ai commented 1 year ago

Sorry for the late response. The above PR should fix the issue. I also allowed PolygonLabels to be added, because otherwise this breaks COCO exports that use segmentation.

luuzk commented 1 year ago

The YOLO export has still an invalid format if you use the Choices tag. I think the linked PR should fix the issue but it is not merged yet. Any updates on this?