Skip to content

Commit a41cdef

Browse files
authored
refactor: ♻️ update YOLO12 example doc and code (#14771)
- Update requirements.txt for YOLO12 dependencies - Add .gitignore for YOLO12 model files - Update README.md to improve clarity and formatting - Replace de_parallel with unwrap_model in export_and_validate.py Signed-off-by: Onuralp SEZER <[email protected]>
1 parent 41b061e commit a41cdef

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

examples/models/yolo12/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pt
2+
*.pte
3+
*.ptd

examples/models/yolo12/README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# YOLO12 Detection C++ Inference with ExecuTorch
22

3-
This example demonstrates how to perform inference of [Ultralytics YOLO12 family](https://docs.ultralytics.com/models/yolo12/) detection models in C++ leveraging the Executorch backends:
3+
This example demonstrates how to perform inference of [YOLO12 family](https://docs.ultralytics.com/models/yolo12/) detection models in C++ leveraging the Executorch backends:
4+
45
- [OpenVINO](../../../backends/openvino/README.md)
56
- [XNNPACK](../../../backends/xnnpack/README.md)
67

7-
# Performance Evaluation
8+
## Performance Evaluation
89

910
| CPU | Model | Backend | Device | Precision | Average Latency, ms |
1011
|--------------------------------|---------|----------|--------|-----------|---------------------|
@@ -17,8 +18,7 @@ This example demonstrates how to perform inference of [Ultralytics YOLO12 family
1718
| Intel(R) Core(TM) Ultra 7 155H | yolo12s | xnnpack | CPU | FP32 | 169.36 |
1819
| Intel(R) Core(TM) Ultra 7 155H | yolo12l | xnnpack | CPU | FP32 | 436.876 |
1920

20-
21-
# Instructions
21+
## Instructions
2222

2323
### Step 1: Install ExecuTorch
2424

@@ -31,35 +31,36 @@ To install ExecuTorch, follow this [guide](https://pytorch.org/executorch/stable
3131

3232
### Step 3: Install the demo requirements
3333

34-
3534
Python demo requirements:
35+
3636
```bash
3737
python -m pip install -r examples/models/yolo12/requirements.txt
3838
```
3939

4040
Demo infenrece dependency - OpenCV library:
41-
https://opencv.org/get-started/
42-
43-
44-
### Step 4: Export the Yolo12 model to the ExecuTorch
41+
<https://opencv.org/get-started/>
4542

43+
### Step 4: Export the YOLO12 model to the ExecuTorch
4644

4745
OpenVINO:
46+
4847
```bash
4948
python export_and_validate.py --model_name yolo12s --input_dims=[1920,1080] --backend openvino --device CPU
5049
```
5150

5251
OpenVINO quantized model:
52+
5353
```bash
5454
python export_and_validate.py --model_name yolo12s --input_dims=[1920,1080] --backend openvino --quantize --video_input /path/to/calibration/video --device CPU
5555
```
5656

5757
XNNPACK:
58+
5859
```bash
5960
python export_and_validate.py --model_name yolo12s --input_dims=[1920,1080] --backend xnnpack
6061
```
6162

62-
> **_NOTE:_** Quantization for XNNPACK backend is WIP. Please refere to https://github.com/pytorch/executorch/issues/11523 for more details.
63+
> **_NOTE:_** Quantization for XNNPACK backend is WIP. Please refere to <https://github.com/pytorch/executorch/issues/11523> for more details.
6364
6465
Exported model could be validated using the `--validate` key:
6566

@@ -70,8 +71,8 @@ python export_and_validate.py --model_name yolo12s --backend ... --validate data
7071
A list of available datasets and instructions on how to use a custom dataset can be found [here](https://docs.ultralytics.com/datasets/detect/).
7172
Validation only supports the default `--input_dims`; please do not specify this parameter when using the `--validate` flag.
7273

73-
7474
To get a full parameters description please use the following command:
75+
7576
```bash
7677
python export_and_validate.py --help
7778
```
@@ -103,11 +104,11 @@ make -j$(nproc)
103104
```
104105

105106
To get a full parameters description please use the following command:
106-
```
107+
108+
```bash
107109
./build/Yolo12DetectionDemo --help
108110
```
109111

112+
## Credits
110113

111-
# Credits:
112-
113-
Ultralytics examples: https://github.com/ultralytics/ultralytics/tree/main/examples
114+
Ultralytics examples: <https://github.com/ultralytics/ultralytics/tree/main/examples>

examples/models/yolo12/export_and_validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from ultralytics.data.utils import check_det_dataset
3737
from ultralytics.engine.validator import BaseValidator as Validator
38-
from ultralytics.utils.torch_utils import de_parallel
38+
from ultralytics.utils.torch_utils import unwrap_model
3939

4040

4141
class CV2VideoIter:
@@ -293,7 +293,7 @@ def _prepare_validation(
293293
stride = 32 # default stride
294294
validator.stride = stride # used in get_dataloader() for padding
295295
validator.data = check_det_dataset(dataset_yaml_path)
296-
validator.init_metrics(de_parallel(model))
296+
validator.init_metrics(unwrap_model(model))
297297

298298
data_loader = validator.get_dataloader(
299299
validator.data.get(validator.args.split), validator.args.batch

0 commit comments

Comments
 (0)