Skip to content

Commit

Permalink
add yolo11 obb documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Dec 20, 2024
1 parent 2f7b7cd commit 35d4510
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 3 deletions.
Binary file added docs/doc/assets/ships-detection-using-obb.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/doc/assets/yolo11_out_obb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/doc/en/sidebar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ items:
label: Object tracking and counting
- file: vision/ocr.md
label: OCR
- file: vision/detect_obb.md
label: Detect with angle(OBB)
- file: vision/maixhub_train.md
label: MaixHub online AI training
- file: vision/customize_model_yolov5.md
Expand Down
66 changes: 66 additions & 0 deletions docs/doc/en/vision/detect_obb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
tite: Target Detection with Rotation Angles (OBB, Oriented Bounding Box)
update:
- date: 2024-12-20
version: v1.0
author: neucrack
content:
Support YOLO11/YOLOv8 OBB model and add documentation
---

## Introduction

In standard object detection, the output is typically a rectangular bounding box. However, in certain scenarios, objects may have a rotated shape, requiring a bounding box with a rotation angle. This type of bounding box is referred to as an OBB (Oriented Bounding Box).
![](../../assets/ships-detection-using-obb.jpeg)

**Standard detection results:** `x, y, w, h` represent the top-left or center coordinates of the rectangle, along with its width and height.
**OBB detection results:** `x, y, w, h, angle` includes an additional parameter for the rotation angle.

## Using Rotated Bounding Boxes (OBB) in MaixPy MaixCAM

`MaixPy` supports the `YOLO11/YOLOv8` OBB model, enabling quick and convenient implementation. Below is an example based on the `nn_yolo11_obb.py` script from [MaixPy/examples](https://github.com/sipeed/maixpy):

```python
from maix import camera, display, image, nn, app

detector = nn.YOLO11(model="/root/models/yolo11n_obb.mud", dual_buff=True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
disp = display.Display()

while not app.need_exit():
img = cam.read()
objs = detector.detect(img, conf_th=0.5, iou_th=0.45)
for obj in objs:
points = obj.get_obb_points()
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}, {obj.angle * 180:.1f}'
img.draw_string(points[0], points[1] - 4, msg, color=image.COLOR_RED)
detector.draw_pose(img, points, 8 if detector.input_width() > 480 else 4, image.COLOR_RED, close=True)
disp.show(img)
```

In this example, the `YOLO11` model is used to load an OBB model. After detecting an object, the rotation angle can be accessed via `obj.angle`. The `x, y, w, h` attributes of `obj` represent the unrotated rectangle. The `get_obb_points` method retrieves the four vertices of the rotated rectangle, and `draw_pose` is used to draw the rotated bounding box. The `close` parameter ensures the vertices are connected.

The default model is the official YOLO11 15-class model with the following labels:

```python
plane, ship, storage tank, baseball diamond, tennis court, basketball court, ground track field, harbor, bridge, large vehicle, small vehicle, helicopter, roundabout, soccer ball field, swimming pool
```

The model file can be found at `/root/models/yolo11n_obb.mud`.

## Customizing Your Own OBB Model for MaixPy MaixCAM

### Using the Model on a Computer

For an introduction to the official `YOLO11` OBB models, refer to [YOLO11 OBB](https://docs.ultralytics.com/tasks/obb/). This documentation explains how to use OBB models on a computer and export ONNX model files.

### Exporting the Model for MaixCAM

Follow the [YOLO11/YOLOv8 Custom Models](./customize_model_yolov8.md) guide to convert an ONNX model into a MUD model compatible with MaixCAM.
**Note:** Ensure the output names of the model's layers are correctly configured during conversion.

### Training Your Own OBB Model

Refer to the [YOLO11 Official Training Documentation](https://docs.ultralytics.com/datasets/obb/dota-v2/) to prepare your dataset and train your own OBB model.

2 changes: 2 additions & 0 deletions docs/doc/zh/sidebar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ items:
label: 物体轨迹跟踪和计数
- file: vision/ocr.md
label: OCR 文字识别
- file: vision/detect_obb.md
label: 带旋转角度的检测(OBB)
- file: vision/maixhub_train.md
label: MaixHub 在线训练 AI 模型
- file: vision/customize_model_yolov5.md
Expand Down
9 changes: 6 additions & 3 deletions docs/doc/zh/vision/customize_model_yolov8.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ model = YOLO(net_name) # load an official model

# Predict with the model
results = model("https://ultralytics.com/images/bus.jpg") # predict on an image
path = model.export(format="onnx", imgsz=[input_height, input_width]) # export the model to ONNX format
path = model.export(format="onnx", imgsz=[input_height, input_width], dynamic=False, simplify=True, opset=17) # export the model to ONNX format
print(path)

```
Expand All @@ -82,7 +82,7 @@ MaixPy/MaixCDK 目前支持了 YOLOv8 / YOLO11 检测 以及 YOLOv8-pose / YOLO1

按照[MaixCAM 模型转换](../ai_model_converter/maixcam.md) 进行模型转换。

注意模型输出节点的选择(注意可能你的模型可能数值不完全一样,看下面的图找到相同的节点即可):
注意模型输出节点的选择(**注意可能你的模型可能数值不完全一样,看下面的图找到相同的节点即可**):
* 检测模型:
* YOLOv8 提取 onnx 的 `/model.22/dfl/conv/Conv_output_0,/model.22/Sigmoid_output_0` 这两个输出。
* YOLO11 提取`/model.23/dfl/conv/Conv_output_0,/model.23/Sigmoid_output_0`输出。
Expand All @@ -92,8 +92,11 @@ MaixPy/MaixCDK 目前支持了 YOLOv8 / YOLO11 检测 以及 YOLOv8-pose / YOLO1
* 图像分割:
* YOLOv8-seg 提取 `/model.22/dfl/conv/Conv_output_0,/model.22/Sigmoid_output_0,/model.22/Concat_output_0,output1`
* YOLO11-seg 提取 `/model.23/dfl/conv/Conv_output_0,/model.23/Sigmoid_output_0,/model.23/Concat_output_0,output1`四个输出。
* OBB 检测:
* YOLOv8 提取`/model.22/dfl/conv/Conv_output_0,/model.22/Sigmoid_1_output_0,/model.22/Sigmoid_output_0`这三个输出。
* YOLO11 提取`/model.23/dfl/conv/Conv_output_0,/model.23/Sigmoid_1_output_0,/model.23/Sigmoid_output_0`这三个输出。

![](../../assets/yolov8_out1.jpg) ![](../../assets/yolov8_out2.jpg)
![](../../assets/yolov8_out1.jpg) ![](../../assets/yolov8_out2.jpg) ![](../../assets/yolo11_out_obb.jpg)

对于物体检测,mud 文件为(YOLO11 model_type 改为 yolo11)
```ini
Expand Down
69 changes: 69 additions & 0 deletions docs/doc/zh/vision/detect_obb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
tite: 带旋转角度的目标检测(OBB, Oriented Bounding Box)
update:
- date: 2024-12-20
version: v1.0
author: neucrack
content:
支持 YOLO11/YOLOv8 OBB 模型并添加文档
---

## 简介

普通的检测中输出结果是一个矩形框,但是在一些场景中,目标物体的形状是旋转的,这时候就需要输出一个带旋转角度的矩形框,这种矩形框叫做OBB(Oriented Bounding Box)。
![](../../assets/ships-detection-using-obb.jpeg)

普通检测结果: x, y, w, h, 分别是 矩形框左上角或者中心点坐标,以及矩形宽高。
OBB 检测结果:x, y, w, h, angle, 多了一个旋转角度。

## MaixPy MaixCAM 中使用带旋转角度的目标检测(OBB)

`MaixPy` 中移植了 `YOLO11/YOLOv8` `OBB` 模型,可以快速方便地实现, 以下为例程,以[MaixPy/examples](https://github.com/sipeed/maixpy)中的`nn_yolo11_obb.py`为准:
```python
from maix import camera, display, image, nn, app

detector = nn.YOLO11(model="/root/models/yolo11n_obb.mud", dual_buff = True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
disp = display.Display()

while not app.need_exit():
img = cam.read()
objs = detector.detect(img, conf_th = 0.5, iou_th = 0.45)
for obj in objs:
points = obj.get_obb_points()
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}, {obj.angle * 180:.1f}'
img.draw_string(points[0], points[1] - 4, msg, color = image.COLOR_RED)
detector.draw_pose(img, points, 8 if detector.input_width() > 480 else 4, image.COLOR_RED, close=True)
disp.show(img)
```

可以看到这里使用`YOLO11`加载了`obb`模型,然后在检测到目标后,通过`obj.angle`获取到矩形旋转角度,`obj``x,y,w,h`属性是未旋转的矩形,通过`get_obb_points`获取到旋转后的矩形的四个顶点坐标,然后通过`draw_pose`绘制出目标的旋转矩形框,`close`参数表示将矩形框四个顶点连线起来。


默认的模型是 YOLO11 官方的`15`类模型,分类标签如下:
```python
plane, ship, storage tank, baseball diamond, tennis court, basketball court, ground track field, harbor, bridge, large vehicle, small vehicle, helicopter, roundabout, soccer ball field, swimming pool
```
`/root/models/yolo11n_obb.mud`文件中也能看到。


## MaixPy MaixCAM 自定义自己的OBB模型

### 电脑端使用模型

关于 `YOLO11` 官方的 OBB 模型介绍请看[YOLO11 OBB](https://docs.ultralytics.com/tasks/obb/)
在这个文档中可以看到如何在电脑端使用`obb`模型,以及如何导出 ONNX 模型文件。

### 导出模型给 MaixCAM 使用

根据 [YOLO11/YOLOv8 自定义模型](./customize_model_yolov8.md) 即可将 ONNX 模型转换为 MaixCAM 可以使用的 MUD 模型。
注意:转换时需要注意输出层的输出名不要弄错。

### 训练自己的 OBB 模型

根据[YOLO11 官方训练文档](https://docs.ultralytics.com/datasets/obb/dota-v2/) 准备自己的数据集,然后进行训练即可。




0 comments on commit 35d4510

Please sign in to comment.