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

Now it can count objects with the command "python tools/infer.py --weights yolov6s.pt --class 56 --source camera". #401

Open
wants to merge 5 commits into
base: main
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ Your can also specify a checkpoint path to `--resume` parameter by
* [YOLOv6 web demo](https://huggingface.co/spaces/nateraw/yolov6) on [Huggingface Spaces](https://huggingface.co/spaces) with [Gradio](https://github.com/gradio-app/gradio). [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/nateraw/yolov6)
* Tutorial: [How to train YOLOv6 on a custom dataset](https://blog.roboflow.com/how-to-train-yolov6-on-a-custom-dataset/) <a href="https://colab.research.google.com/drive/1YnbqOinBZV-c9I7fk_UL6acgnnmkXDMM"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>
* Demo of YOLOv6 inference on Google Colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mahdilamb/YOLOv6/blob/main/inference.ipynb)


Now it can count objects with the command "python tools/infer.py --weights yolov6s.pt --class 56 --source camera".
6 changes: 3 additions & 3 deletions configs/repopt/yolov6s_hs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down Expand Up @@ -51,4 +51,4 @@
)

# Choose Rep-block by the training Mode, choices=["repvgg", "hyper-search", "repopt"]
training_mode='hyper_search'
training_mode = 'hyper_search'
6 changes: 3 additions & 3 deletions configs/repopt/yolov6s_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down Expand Up @@ -52,4 +52,4 @@
)

# Choose Rep-block by the training Mode, choices=["repvgg", "hyper-search", "repopt"]
training_mode='repopt'
training_mode = 'repopt'
4 changes: 2 additions & 2 deletions configs/yolov6_tiny.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down
4 changes: 2 additions & 2 deletions configs/yolov6_tiny_finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down
4 changes: 2 additions & 2 deletions configs/yolov6n.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down
4 changes: 2 additions & 2 deletions configs/yolov6n_finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down
4 changes: 2 additions & 2 deletions configs/yolov6s.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down
4 changes: 2 additions & 2 deletions configs/yolov6s_finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type='EfficientRep',
num_repeats=[1, 6, 12, 18, 6],
out_channels=[64, 128, 256, 512, 1024],
),
),
neck=dict(
type='RepPAN',
num_repeats=[12, 12, 12, 12],
out_channels=[256, 128, 128, 256, 256, 512],
),
),
head=dict(
type='EffiDeHead',
in_channels=[128, 256, 512],
Expand Down
8 changes: 4 additions & 4 deletions data/coco.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# COCO 2017 dataset http://cocodataset.org
train: ../coco/images/train2017 # 118287 images
val: ../coco/images/val2017 # 5000 images
test: ../coco/images/test2017
train: C:/Users/ahmtb/YOLOv6coco/images/train2017 # 118287 images
val: C:/Users/ahmtb/YOLOv6coco/images/train2017 # 5000 images
test: C:/Users/ahmtb/YOLOv6coco/images/train2017
anno_path: ../coco/annotations/instances_val2017.json
# number of classes
nc: 80
Expand All @@ -17,4 +17,4 @@ names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', '
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
'hair drier', 'toothbrush' ]
'hair drier', 'toothbrush' ]
4 changes: 2 additions & 2 deletions data/dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ test: ../custom_dataset/images/test # test images (optional)
is_coco: False
# Classes
nc: 20 # number of classes
names: ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog',
'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] # class names
names: [ 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog',
'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor' ] # class names
4 changes: 2 additions & 2 deletions data/voc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ test: VOCdevkit/voc_07_12/images/val # test images (optional)
is_coco: False
# Classes
nc: 20 # number of classes
names: ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog',
'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] # class names
names: [ 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog',
'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor' ] # class names
15 changes: 10 additions & 5 deletions deploy/ONNX/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Export ONNX Model

## Check requirements

```shell
pip install onnx>=1.10.0
```

## Export script

```shell
python ./deploy/ONNX/export_onnx.py \
--weights yolov6s.pt \
--img 640 \
--batch 1
```



#### Description of all arguments

- `--weights` : The path of yolov6 model weights.
Expand Down Expand Up @@ -45,6 +45,7 @@ Now YOLOv6 supports end to end detect for onnxruntime and TensorRT !
If you want to deploy in TensorRT, make sure you have installed TensorRT >= 8.0.0 !

### onnxruntime backend

#### Usage

```bash
Expand Down Expand Up @@ -77,7 +78,8 @@ python ./deploy/ONNX/export_onnx.py \
--trt-version 7
```

You will get an onnx with **[BatchedNMSDynamic_TRT](https://github.com/triple-Mu/TensorRT/tree/main/plugin/batchedNMSPlugin)** plugin .
You will get an onnx
with **[BatchedNMSDynamic_TRT](https://github.com/triple-Mu/TensorRT/tree/main/plugin/batchedNMSPlugin)** plugin .

### TensorRT backend (TensorRT version>= 8.0.0)

Expand All @@ -92,7 +94,8 @@ python ./deploy/ONNX/export_onnx.py \
--trt-version 8
```

You will get an onnx with **[EfficientNMS_TRT](https://github.com/NVIDIA/TensorRT/tree/main/plugin/efficientNMSPlugin)** plugin .
You will get an onnx with **[EfficientNMS_TRT](https://github.com/NVIDIA/TensorRT/tree/main/plugin/efficientNMSPlugin)**
plugin .

### Outputs Description

Expand All @@ -108,8 +111,9 @@ The onnx outputs are as shown :

```det_classes``` means the category of every topk(100) objects .

You can export TensorRT engine
use [trtexec](https://docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#trtexec-ovr) tools.

You can export TensorRT engine use [trtexec](https://docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#trtexec-ovr) tools.
#### Usage

For both TensorRT-7 and TensorRT-8 `trtexec` tool is avaiable.
Expand All @@ -124,6 +128,7 @@ trtexec --onnx=yolov6s.onnx \
## Evaluate TensorRT model's performance

When we get the TensorRT model, we can evalute its performance by:

```
python deploy/ONNX/eval_trt.py --weights yolov6s.engine --batch-size=1 --data data/coco.yaml
```
10 changes: 5 additions & 5 deletions deploy/ONNX/eval_trt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def run(data,
task='val',
device='',
save_dir='',
name = ''
name=''
):
"""
TensorRT models's evaluation process.
"""

# task
assert task== 'val', f'task type can only be val, however you set it to {task}'
# task
assert task == 'val', f'task type can only be val, however you set it to {task}'

save_dir = str(increment_name(osp.join(save_dir, name)))
os.makedirs(save_dir, exist_ok=True)
Expand All @@ -57,9 +57,9 @@ def run(data,

# init
val = Evaler(data, batch_size, img_size, None, \
None, device, False, save_dir)
None, device, False, save_dir)

dataloader,pred_result = val.eval_trt(weights)
dataloader, pred_result = val.eval_trt(weights)
eval_result = val.eval_model(pred_result, dummy_model, dataloader, task)
return eval_result

Expand Down
15 changes: 9 additions & 6 deletions deploy/ONNX/export_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from yolov6.utils.checkpoint import load_checkpoint
from io import BytesIO


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--weights', type=str, default='./yolov6s.pt', help='weights path')
Expand All @@ -31,7 +30,8 @@
parser.add_argument('--end2end', action='store_true', help='export end2end onnx')
parser.add_argument('--trt-version', type=int, default=8, help='tensorrt version')
parser.add_argument('--with-preprocess', action='store_true', help='export bgr2rgb and normalize')
parser.add_argument('--max-wh', type=int, default=None, help='None for tensorrt nms, int value for onnx-runtime nms')
parser.add_argument('--max-wh', type=int, default=None,
help='None for tensorrt nms, int value for onnx-runtime nms')
parser.add_argument('--topk-all', type=int, default=100, help='topk objects for every images')
parser.add_argument('--iou-thres', type=float, default=0.45, help='iou threshold for NMS')
parser.add_argument('--conf-thres', type=float, default=0.25, help='conf threshold for NMS')
Expand Down Expand Up @@ -66,8 +66,10 @@
m.inplace = args.inplace
if args.end2end:
from yolov6.models.end2end import End2End
model = End2End(model, max_obj=args.topk_all, iou_thres=args.iou_thres,score_thres=args.conf_thres,
max_wh=args.max_wh, device=device, trt_version=args.trt_version, with_preprocess=args.with_preprocess)

model = End2End(model, max_obj=args.topk_all, iou_thres=args.iou_thres, score_thres=args.conf_thres,
max_wh=args.max_wh, device=device, trt_version=args.trt_version,
with_preprocess=args.with_preprocess)

y = model(img) # dry run

Expand All @@ -81,7 +83,7 @@
do_constant_folding=True,
input_names=['images'],
output_names=['num_dets', 'det_boxes', 'det_scores', 'det_classes']
if args.end2end and args.max_wh is None else ['outputs'],)
if args.end2end and args.max_wh is None else ['outputs'], )
f.seek(0)
# Checks
onnx_model = onnx.load(f) # load onnx model
Expand All @@ -96,6 +98,7 @@
if args.simplify:
try:
import onnxsim

LOGGER.info('\nStarting to simplify ONNX...')
onnx_model, check = onnxsim.simplify(onnx_model)
assert check, 'assert check failed'
Expand All @@ -111,4 +114,4 @@
if args.end2end:
if args.max_wh is None:
LOGGER.info('\nYou can export tensorrt engine use trtexec tools.\nCommand is:')
LOGGER.info(f'trtexec --onnx={export_file} --saveEngine={export_file.replace(".onnx",".engine")}')
LOGGER.info(f'trtexec --onnx={export_file} --saveEngine={export_file.replace(".onnx", ".engine")}')
4 changes: 4 additions & 0 deletions deploy/OpenVINO/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
## Export OpenVINO Model

### Check requirements

```shell
pip install --upgrade pip
pip install openvino-dev
```

### Export script

```shell
python deploy/OpenVINO/export_openvino.py --weights yolov6s.pt --img 640 --batch 1

```

### Download

* [YOLOv6-nano](https://github.com/meituan/YOLOv6/releases/download/0.1.0/yolov6n_openvino.tar.gz)
* [YOLOv6-tiny](https://github.com/meituan/YOLOv6/releases/download/0.1.0/yolov6n_openvino.tar.gz)
* [YOLOv6-s](https://github.com/meituan/YOLOv6/releases/download/0.1.0/yolov6n_openvino.tar.gz)

### Speed test

```shell
benchmark_app -m yolov6s_openvino/yolov6s.xml -i data/images/image1.jpg -d CPU -niter 100 -progress

Expand Down
3 changes: 1 addition & 2 deletions deploy/OpenVINO/export_openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from yolov6.utils.events import LOGGER
from yolov6.utils.checkpoint import load_checkpoint


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--weights', type=str, default='./yolov6s.pt', help='weights path')
Expand Down Expand Up @@ -68,7 +67,7 @@
do_constant_folding=True,
input_names=['image_arrays'],
output_names=['outputs'],
)
)

# Checks
onnx_model = onnx.load(export_file) # load onnx model
Expand Down
7 changes: 6 additions & 1 deletion docs/About_naming_yolov6.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# About the naming of YOLOv6

### WHY named YOLOv6 ?
The full name is actually MT-YOLOv6, which is called YOLOv6 for brevity. Our work is majorly inspired by the original idea of the one-stage YOLO detection algorithm and the implementation has leveraged various techniques and tricks of former relevant work . Therefore, we named the project YOLOv6 to pay tribute to the work of YOLO series. Furthermore, we have indeed adopted some novel method and made solid engineering improvements to dedicate the algorithm to industrial applications.

The full name is actually MT-YOLOv6, which is called YOLOv6 for brevity. Our work is majorly inspired by the original
idea of the one-stage YOLO detection algorithm and the implementation has leveraged various techniques and tricks of
former relevant work . Therefore, we named the project YOLOv6 to pay tribute to the work of YOLO series. Furthermore, we
have indeed adopted some novel method and made solid engineering improvements to dedicate the algorithm to industrial
applications.
As for the project, we'll continue to improve and maintain it, contributing more values for industrial applications.

P.S. We are contacting the authors of YOLO series about the naming of YOLOv6.
Expand Down
3 changes: 2 additions & 1 deletion docs/Test_speed.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Test speed

This guidence explains how to reproduce speed results of YOLOv6. For fair comparison, the speed results do not contain the time cost of data pre-processing and NMS post-processing.
This guidence explains how to reproduce speed results of YOLOv6. For fair comparison, the speed results do not contain
the time cost of data pre-processing and NMS post-processing.

## 0. Prepare model

Expand Down
Loading