Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Port model_obb to canRotate #650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions label_studio_ml/examples/yolo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ making it easier to annotate large datasets and ensure high-quality predictions.
| YOLO Task Name | LS Control Tag | Prediction Supported | LS Import Supported | LS Export Supported |
|--------------------------------------------------------------|--------------------------------------|----------------------|---------------------|---------------------|
| Object Detection | `<RectangleLabels>` | ✅ | YOLO, COCO | YOLO, COCO |
| Oriented Bounding Boxes (OBB) | `<RectangleLabels model_obb="true">` | ✅ | YOLO | YOLO |
| Oriented Bounding Boxes (OBB) | `<RectangleLabels canRotate="true">` | ✅ | YOLO | YOLO |
| Image Instance Segmentation: Polygons | `<PolygonLabels>` | ✅ | COCO | YOLO, COCO |
| Image Semantic Segmentation: Masks | `<BrushLabels>` | ❌ | Native | Native |
| Image Classification | `<Choices>` | ✅ | Native | Native |
Expand Down Expand Up @@ -479,7 +479,7 @@ https://github.com/user-attachments/assets/413b4650-422d-43dc-809d-51c08f0ad434
|-------------------------|--------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `model_score_threshold` | float | 0.5 | Sets the minimum confidence threshold for detections. Objects detected with confidence below this threshold will be disregarded. Adjusting this value can help reduce false positives. |
| `model_path` | string | None | Path to the custom YOLO model. See more in the section [Your own custom YOLO models](#your-own-custom-yolo-models). |
| `model_obb` | bool | False | Enables Oriented Bounding Boxes (OBB) mode. Typically it uses `*-obb.pt` yolo models. |
| `canRotate` | bool | true | Enables Oriented Bounding Boxes (OBB) mode. Typically it uses `*-obb.pt` yolo models. |

For example:
```xml
Expand All @@ -493,11 +493,11 @@ For example:

### Oriented Bounding Boxes (YOLO OBB)

Oriented (rotated) bounding boxes will be generated automatically if you use an OBB model.
Specify `model_obb="true"` in the `RectangleLabels` tag to enable this mode:
Oriented (rotated) bounding boxes will be generated automatically if you use an OBB model.
This mode is enabled by default since `canRotate="true"` is the default for the `RectangleLabels` but you can set it explicitly:

```xml
<RectangleLabels name="label" toName="image" model_score_threshold="0.25" model_obb="true">
<RectangleLabels name="label" toName="image" model_score_threshold="0.25" canRotate="true">
```

More info: https://docs.ultralytics.com/tasks/obb/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

def is_obb(control: ControlTag) -> bool:
"""Check if the model should use oriented bounding boxes (OBB)
based on the control tag attribute `model_obb` from the labeling config.
based on the control tag attribute `canRotate` from the labeling config.
"""
return get_bool(control.attr, "model_obb", "false")
return get_bool(control.attr, "canRotate", "true")


class RectangleLabelsModel(ControlModel):
Expand Down Expand Up @@ -40,7 +40,7 @@ def predict_regions(self, path) -> List[Dict]:
if results[0].obb is not None and results[0].boxes is None:
raise ValueError(
"Oriented bounding boxes are detected in the YOLO model results. "
'However, `model_obb="true"` is not set at the RectangleLabels tag '
'However, `canRotate="true"` is not set at the RectangleLabels tag '
"in the labeling config."
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def predict_regions(self, path) -> List[Dict]:
# simple bounding boxes without rotation
if results[0].obb is None:
raise ValueError(
"Simple bounding boxes are detected in the YOLO model results. "
'However, `model_obb="true"` is set at the RectangleLabels tag '
"in the labeling config. Set it to `false` to use simple bounding boxes."
'Simple bounding boxes are detected in the YOLO model results. '
'However, `canRotate` is not set or `canRotate="true"` is set '
'at the RectangleLabels tag in the labeling config. Set it to '
'`false` to use simple bounding boxes.'
)

# oriented bounding boxes with rotation (yolo obb model)
Expand Down
8 changes: 4 additions & 4 deletions label_studio_ml/examples/yolo/tests/test_rectangle_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""
<View>
<Image name="image" value="$image"/>
<RectangleLabels name="label" toName="image" model_score_threshold="0.25">
<RectangleLabels name="label" toName="image" canRotate="false" model_score_threshold="0.25">
<Label value="Airplane" background="green"/>
<Label value="Car" background="blue" predicted_values="car, truck"/>
</RectangleLabels>
Expand All @@ -28,13 +28,13 @@
"""
<View>
<Image name="image" value="$image"/>
<RectangleLabels name="label" toName="image" model_score_threshold="0.30">
<RectangleLabels name="label" toName="image" canRotate="false" model_score_threshold="0.30">
<Label value="Airplane" background="green"/>
<Label value="Car" background="blue" predicted_values="car, truck"/>
</RectangleLabels>

<Image name="image2" value="$image2"/>
<RectangleLabels name="label2" toName="image2" model_score_threshold="0.90">
<RectangleLabels name="label2" toName="image2" canRotate="false" model_score_threshold="0.90">
<Label value="Person" background="green"/>
<Label value="Animal" background="blue" predicted_values="cat,dog"/>
</RectangleLabels>
Expand Down
10 changes: 5 additions & 5 deletions label_studio_ml/examples/yolo/tests/test_rectangle_labels_obb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<View>
<Header value="Select label and click the image to start"/>
<Image name="image" value="$image" zoom="true"/>

<RectangleLabels name="rect" toName="image"
model_score_threshold="0.1" model_obb="true">
<Label value="plane" background="red"
model_score_threshold="0.1" canRotate="true">
<Label value="plane" background="red"
predicted_values="plane,helicopter"/>
<Label value="vehicle" background="blue"
<Label value="vehicle" background="blue"
predicted_values="ship,storage tank,bridge,large vehicle,small vehicle"/>
</RectangleLabels>

</View>
""",
]
Expand Down