Skip to content

Commit

Permalink
openvino mo 2 ovc
Browse files Browse the repository at this point in the history
  • Loading branch information
NagatoYuki0943 committed Mar 22, 2024
1 parent 4499245 commit e3e2f42
Showing 1 changed file with 36 additions and 52 deletions.
88 changes: 36 additions & 52 deletions 使用方法.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,29 @@ names:

### 预训练模型

| 模型 | 尺寸 (像素) | mAPval 50-95 | mAPval 50 | 推理速度 CPU b1 (ms) | 推理速度 V100 b1 (ms) | 速度 V100 b32 (ms) | 参数量 (M) | FLOPs @640 (B) |
| --------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------------- | ------------- | ---------------- | ----------------- | ---------------- | ------- | -------------- |
| [YOLOv5n](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n.pt) | 640 | 28.0 | 45.7 | **45** | **6.3** | **0.6** | **1.9** | **4.5** |
| [YOLOv5s](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt) | 640 | 37.4 | 56.8 | 98 | 6.4 | 0.9 | 7.2 | 16.5 |
| [YOLOv5m](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5m.pt) | 640 | 45.4 | 64.1 | 224 | 8.2 | 1.7 | 21.2 | 49.0 |
| [YOLOv5l](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5l.pt) | 640 | 49.0 | 67.3 | 430 | 10.1 | 2.7 | 46.5 | 109.1 |
| [YOLOv5x](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5x.pt) | 640 | 50.7 | 68.9 | 766 | 12.1 | 4.8 | 86.7 | 205.7 |
| | | | | | | | | |
| [YOLOv5n6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n6.pt) | 1280 | 36.0 | 54.4 | 153 | 8.1 | 2.1 | 3.2 | 4.6 |
| [YOLOv5s6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s6.pt) | 1280 | 44.8 | 63.7 | 385 | 8.2 | 3.6 | 12.6 | 16.8 |
| [YOLOv5m6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5m6.pt) | 1280 | 51.3 | 69.3 | 887 | 11.1 | 6.8 | 35.7 | 50.0 |
| [YOLOv5l6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5l6.pt) | 1280 | 53.7 | 71.3 | 1784 | 15.8 | 10.5 | 76.8 | 111.4 |
| [YOLOv5x6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5x6.pt) +[TTA](https://github.com/ultralytics/yolov5/issues/303) | 1280 1536 | 55.0 **55.8** | 72.7 **72.7** | 3136 - | 26.2 - | 19.4 - | 140.7 - | 209.8 - |
| 模型 | 尺寸 (像素) | mAPval 50-95 | mAPval 50 | 推理速度 CPU b1 (ms) | 推理速度 V100 b1 (ms) | 速度 V100 b32 (ms) | 参数量 (M) | FLOPs @640 (B) |
| ------------------------------------------------------------ | ------------- | ------------- | ------------- | ---------------------- | ----------------------- | -------------------- | ---------- | -------------- |
| [YOLOv5n](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n.pt) | 640 | 28.0 | 45.7 | **45** | **6.3** | **0.6** | **1.9** | **4.5** |
| [YOLOv5s](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt) | 640 | 37.4 | 56.8 | 98 | 6.4 | 0.9 | 7.2 | 16.5 |
| [YOLOv5m](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5m.pt) | 640 | 45.4 | 64.1 | 224 | 8.2 | 1.7 | 21.2 | 49.0 |
| [YOLOv5l](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5l.pt) | 640 | 49.0 | 67.3 | 430 | 10.1 | 2.7 | 46.5 | 109.1 |
| [YOLOv5x](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5x.pt) | 640 | 50.7 | 68.9 | 766 | 12.1 | 4.8 | 86.7 | 205.7 |
| | | | | | | | | |
| [YOLOv5n6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n6.pt) | 1280 | 36.0 | 54.4 | 153 | 8.1 | 2.1 | 3.2 | 4.6 |
| [YOLOv5s6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s6.pt) | 1280 | 44.8 | 63.7 | 385 | 8.2 | 3.6 | 12.6 | 16.8 |
| [YOLOv5m6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5m6.pt) | 1280 | 51.3 | 69.3 | 887 | 11.1 | 6.8 | 35.7 | 50.0 |
| [YOLOv5l6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5l6.pt) | 1280 | 53.7 | 71.3 | 1784 | 15.8 | 10.5 | 76.8 | 111.4 |
| [YOLOv5x6](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5x6.pt) +[TTA](https://github.com/ultralytics/yolov5/issues/303) | 1280 1536 | 55.0 **55.8** | 72.7 **72.7** | 3136 - | 26.2 - | 19.4 - | 140.7 - | 209.8 - |

笔记

- 所有模型都使用默认配置,训练 300 epochs。n和s模型使用 [hyp.scratch-low.yaml](https://github.com/ultralytics/yolov5/blob/master/data/hyps/hyp.scratch-low.yaml) ,其他模型都使用 [hyp.scratch-high.yaml](https://github.com/ultralytics/yolov5/blob/master/data/hyps/hyp.scratch-high.yaml) 。
- **mAPval**在单模型单尺度上计算,数据集使用 [COCO val2017](http://cocodataset.org/) 。 复现命令 `python val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65`
- **推理速度**在 COCO val 图像总体时间上进行平均得到,测试环境使用[AWS p3.2xlarge](https://aws.amazon.com/ec2/instance-types/p3/)实例。 NMS 时间 (大约 1 ms/img) 不包括在内。 复现命令 `python val.py --data coco.yaml --img 640 --task speed --batch 1`
- **TTA** [测试时数据增强](https://github.com/ultralytics/yolov5/issues/303) 包括反射和尺度变换。 复现命令 `python val.py --data coco.yaml --img 1536 --iou 0.7 --augment`
- **mAPval**在单模型单尺度上计算,数据集使用 [COCO val2017](http://cocodataset.org/) 。
复现命令 `python val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65`
- **推理速度**在 COCO val 图像总体时间上进行平均得到,测试环境使用[AWS p3.2xlarge](https://aws.amazon.com/ec2/instance-types/p3/)实例。 NMS 时间 (大约 1 ms/img) 不包括在内。
复现命令 `python val.py --data coco.yaml --img 640 --task speed --batch 1`
- **TTA** [测试时数据增强](https://github.com/ultralytics/yolov5/issues/303) 包括反射和尺度变换。
复现命令 `python val.py --data coco.yaml --img 1536 --iou 0.7 --augment`

# 显卡训练

Expand Down Expand Up @@ -208,6 +211,8 @@ def parse_opt(known=False):
>
> [About the rectangle training · Issue #4819](https://github.com/ultralytics/ultralytics/issues/4819)

>
>
> 学习率的调整在 `hyps`中调整
>
> `initial learning rate (SGD=1E-2, Adam=1E-3)`
Expand Down Expand Up @@ -237,8 +242,8 @@ python train.py --img 640 --batch-size -1 --workers 8 --epochs 300 --patience 0
## 多显卡训练

- -m torch.distributed.launch pytorch启用多线程
- --nproc_per_node=8 8张显卡
- --device 0,1,2,3,4,5,6,7 8张显卡序号
- --nproc_per_node=8 8张显卡
- --device 0,1,2,3,4,5,6,7 8张显卡序号

```sh
python -m torch.distributed.launch --nproc_per_node=8 train.py --device 0,1,2,3,4,5,6,7 --sync-bn --img 640 --batch-size -1 --workers 8--epochs 300 --patience 0 \
Expand Down Expand Up @@ -328,7 +333,7 @@ YOLOv5n summary: 214 layers, 1790977 parameters, 1790977 gradients, 4.3 GFLOPs
>
> 不需要添加空白label txt文件,添加了也不会出错
>
> `(if no objects in image, no `\*.txt` file is required).`
> `(if no objects in image, no `*.txt` file is required).`
>
> [目标检测(降低误检测率及小目标检测系列笔记)](https://blog.csdn.net/weixin_44836143/article/details/105952819)

Expand All @@ -351,19 +356,19 @@ val: New cache created: D:\code\datasets\classes20\labels\val.cache

- **Image variety.** Must be representative of deployed environment. For real-world use cases we recommend images from different times of day, different seasons, different weather, different lighting, different angles, different sources (scraped online, collected locally, different cameras) etc.

必须能够代表部署环境。 对于现实世界的用例,我们推荐来自一天中不同时间、不同季节、不同天气、不同照明、不同角度、不同来源(在线抓取、本地收集、不同相机)等的图像。
必须能够代表部署环境。 对于现实世界的用例,我们推荐来自一天中不同时间、不同季节、不同天气、不同照明、不同角度、不同来源(在线抓取、本地收集、不同相机)等的图像。

- **Label consistency.** All instances of all classes in all images must be labelled. Partial labelling will not work.

所有图像中所有类的所有实例都必须被标记。 部分标签不起作用。
所有图像中所有类的所有实例都必须被标记。 部分标签不起作用。

- **Label accuracy.** Labels must closely enclose each object. No space should exist between an object and it's bounding box. No objects should be missing a label.

标签必须紧密包围每个对象。 对象与其边界框之间不应存在空间。 任何物品都不应缺少标签。
标签必须紧密包围每个对象。 对象与其边界框之间不应存在空间。 任何物品都不应缺少标签。

- **Background images.** Background images are images with no objects that are added to a dataset to reduce False Positives (FP). We recommend about 0-10% background images to help reduce FPs (COCO has 1000 background images for reference, 1% of the total). No labels are required for background images.

背景图像是没有对象的图像,添加到数据集中以减少误报 (FP)。 我们建议使用大约 0-10% 的背景图片,以帮助降低 FP(COCO 有 1000 张背景图片可供参考,占总数的 1%)。 背景图像不需要标签
背景图像是没有对象的图像,添加到数据集中以减少误报 (FP)。 我们建议使用大约 0-10% 的背景图片,以帮助降低 FP(COCO 有 1000 张背景图片可供参考,占总数的 1%)。 背景图像不需要标签

# export

Expand Down Expand Up @@ -494,38 +499,14 @@ python export.py --imgsz 640 --weights weights/yolov5s.pt --include openvino --s
python export.py --imgsz 640 --weights weights/yolov5s.pt --include openvino --simplify --device cpu --int8 # 需要安装nncf
```
### 通过openvino的`mo`命令将onnx转换为openvino格式(支持**fp16**)
### 通过openvino的`ovc`命令将onnx转换为openvino格式(支持**fp16**)
> https://docs.openvino.ai/latest/notebooks/102-pytorch-onnx-to-openvino-with-output.html
> https://docs.openvino.ai/archive/2023.2/openvino_docs_OV_Converter_UG_prepare_model_convert_model_MO_OVC_transition.html
```sh
mo --input_model "onnx_path" --output_dir "output_path" --compress_to_fp16

mo --input_model "onnx_path" --output_dir "output_path" --compress_to_fp16
```

#### 代码方式

```python
from openvino.tools import mo
from openvino.runtime import serialize
ovc "onnx_path" --output_model "output_path" --compress_to_fp16

onnx_path = "onnx_path"

# fp32 IR model
fp32_path = "fp32_path"
output_path = fp32_path + ".xml"
print(f"Export ONNX to OpenVINO FP32 IR to: {output_path}")
model = mo.convert_model(onnx_path)
serialize(model, output_path)

# fp16 IR model
fp16_path = "fp16_path"
output_path = fp16_path + ".xml"

print(f"Export ONNX to OpenVINO FP16 IR to: {output_path}")
model = mo.convert_model(onnx_path, compress_to_fp16=True)
serialize(model, output_path)
ovc "onnx_path" --output_model "output_path" --compress_to_fp16
```

### export failure 0.9s: DLL load failed while importing ie_api
Expand Down Expand Up @@ -635,6 +616,8 @@ def parse_opt():
`python detect.py --weights 权重路径 --source 图片or视频or文件夹路径`



```python
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
"""
Expand Down Expand Up @@ -797,7 +780,7 @@ def parse_opt():
>
> https://github.com/ultralytics/yolov5/pull/1646
>
> `--save-hybrid` 会合并已知的labels,导致得分很高
> `--save-hybrid` 会合并已知的labels,导致得分很高
## torch

Expand Down Expand Up @@ -836,3 +819,4 @@ python val.py --imgsz 640 --save-txt --save-conf --save-json --conf-thres 0.25 -
```sh
python val.py --imgsz 640 --save-txt --save-conf --save-json --conf-thres 0.25 --iou-thres 0.6 --data data/coco128.yaml --weights weights/yolov5s.engine --device 0
```

0 comments on commit e3e2f42

Please sign in to comment.