2022-07-08 10:25:03 +08:00
# Official YOLOv7
2022-07-07 00:02:25 +08:00
2022-07-07 08:24:04 +08:00
Implementation of paper - [YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors ](https://arxiv.org/abs/2207.02696 )
2022-07-07 00:02:25 +08:00
< img src = "./figure/performance.png" height = "480" >
2022-07-09 12:23:14 +08:00
## Web Demo
2022-07-09 12:24:10 +08:00
- Integrated into [Huggingface Spaces 🤗 ](https://huggingface.co/spaces/akhaliq/yolov7 ) using [Gradio ](https://github.com/gradio-app/gradio ). Try out the Web Demo [](https://huggingface.co/spaces/akhaliq/yolov7)
2022-07-09 12:23:14 +08:00
2022-07-07 00:02:25 +08:00
## Performance
MS COCO
| Model | Test Size | AP< sup > test< / sup > | AP< sub > 50< / sub > < sup > test< / sup > | AP< sub > 75< / sub > < sup > test< / sup > | batch 1 fps | batch 32 average time |
| :-- | :-: | :-: | :-: | :-: | :-: | :-: |
2022-07-07 11:11:51 +08:00
| [**YOLOv7** ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt ) | 640 | **51.4%** | **69.7%** | **55.9%** | 161 *fps* | 2.8 *ms* |
| [**YOLOv7-X** ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7x.pt ) | 640 | **53.1%** | **71.2%** | **57.8%** | 114 *fps* | 4.3 *ms* |
2022-07-07 00:02:25 +08:00
| | | | | | | |
2022-07-07 11:11:51 +08:00
| [**YOLOv7-W6** ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-w6.pt ) | 1280 | **54.9%** | **72.6%** | **60.1%** | 84 *fps* | 7.6 *ms* |
| [**YOLOv7-E6** ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6.pt ) | 1280 | **56.0%** | **73.5%** | **61.2%** | 56 *fps* | 12.3 *ms* |
| [**YOLOv7-D6** ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-d6.pt ) | 1280 | **56.6%** | **74.0%** | **61.8%** | 44 *fps* | 15.0 *ms* |
| [**YOLOv7-E6E** ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6e.pt ) | 1280 | **56.8%** | **74.4%** | **62.1%** | 36 *fps* | 18.7 *ms* |
2022-07-07 00:02:25 +08:00
## Installation
Docker environment (recommended)
< details > < summary > < b > Expand< / b > < / summary >
```
# create the docker container, you can change the share memory size if you have more.
nvidia-docker run --name yolov7 -it -v your_coco_path/:/coco/ -v your_code_path/:/yolov7 --shm-size=64g nvcr.io/nvidia/pytorch:21.08-py3
# apt install required packages
apt update
apt install -y zip htop screen libgl1-mesa-glx
# pip install required packages
pip install seaborn thop
# go to code folder
cd /yolov7
```
< / details >
## Testing
2022-07-07 11:11:51 +08:00
[`yolov7.pt` ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt ) [`yolov7x.pt` ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7x.pt ) [`yolov7-w6.pt` ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-w6.pt ) [`yolov7-e6.pt` ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6.pt ) [`yolov7-d6.pt` ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-d6.pt ) [`yolov7-e6e.pt` ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6e.pt )
2022-07-07 00:02:25 +08:00
```
python test.py --data data/coco.yaml --img 640 --batch 32 --conf 0.001 --iou 0.65 --device 0 --weights yolov7.pt --name yolov7_640_val
```
You will get the results:
```
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.51206
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.69730
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.55521
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.35247
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.55937
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.66693
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.38453
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.63765
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.68772
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.53766
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.73549
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.83868
```
2022-07-09 02:31:37 +08:00
To measure accuracy, download [COCO-annotations for Pycocotools ](http://images.cocodataset.org/annotations/annotations_trainval2017.zip ).
2022-07-07 00:26:03 +08:00
## Training
2022-07-08 17:04:00 +08:00
```
python train.py --workers 8 --device 0 --batch-size 32 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml
python train.py --workers 8 --device 0 --batch-size 32 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7x.yaml --weights '' --name yolov7x --hyp data/hyp.scratch.p5.yaml
```
```
python -m torch.distributed.launch --nproc_per_node 4 --master_port 9527 train.py --workers 8 --device 0,1,2,3 --sync-bn --batch-size 128 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml
python -m torch.distributed.launch --nproc_per_node 4 --master_port 9527 train.py --workers 8 --device 0,1,2,3 --sync-bn --batch-size 128 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7x.yaml --weights '' --name yolov7x --hyp data/hyp.scratch.p5.yaml
```
The training code and instruction of p6 models will release soon.
2022-07-09 02:31:37 +08:00
Download MS COCO dataset images ([train](http://images.cocodataset.org/zips/train2017.zip), [val ](http://images.cocodataset.org/zips/val2017.zip ), [test ](http://images.cocodataset.org/zips/test2017.zip )) and [labels ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/coco2017labels-segments.zip ). If you have previously used a different version of YOLO, we strongly recommend that you delete `train2017.cache` and `val2017.cache` files, and redownload [labels ](https://github.com/WongKinYiu/yolov7/releases/download/v0.1/coco2017labels-segments.zip )
2022-07-08 17:04:00 +08:00
## Re-parameterization
The re-parameterization code and instruction will release soon.
2022-07-07 00:26:03 +08:00
2022-07-09 07:26:32 +08:00
## Inference
`python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg`
2022-07-07 00:02:25 +08:00
## Citation
```
@article {wang2022yolov7,
title={{YOLOv7}: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors},
author={Wang, Chien-Yao and Bochkovskiy, Alexey and Liao, Hong-Yuan Mark},
2022-07-07 08:24:04 +08:00
journal={arXiv preprint arXiv:2207.02696},
2022-07-07 00:02:25 +08:00
year={2022}
}
```
## Acknowledgements
< details > < summary > < b > Expand< / b > < / summary >
* [https://github.com/AlexeyAB/darknet ](https://github.com/AlexeyAB/darknet )
* [https://github.com/WongKinYiu/yolor ](https://github.com/WongKinYiu/yolor )
* [https://github.com/WongKinYiu/PyTorch_YOLOv4 ](https://github.com/WongKinYiu/PyTorch_YOLOv4 )
* [https://github.com/WongKinYiu/ScaledYOLOv4 ](https://github.com/WongKinYiu/ScaledYOLOv4 )
* [https://github.com/Megvii-BaseDetection/YOLOX ](https://github.com/Megvii-BaseDetection/YOLOX )
* [https://github.com/ultralytics/yolov3 ](https://github.com/ultralytics/yolov3 )
* [https://github.com/ultralytics/yolov5 ](https://github.com/ultralytics/yolov5 )
2022-07-08 17:04:00 +08:00
* [https://github.com/DingXiaoH/RepVGG ](https://github.com/DingXiaoH/RepVGG )
* [https://github.com/JUGGHM/OREPA_CVPR2022 ](https://github.com/JUGGHM/OREPA_CVPR2022 )
2022-07-07 00:02:25 +08:00
< / details >