https://github.com/bestsongc/yolov5-multibackbone-compression

YOLOv5 Series Multi-backbone(TPH-YOLOv5, Ghostnet, ShuffleNetv2, Mobilenetv3Small, EfficientNetLite, PP-LCNet, SwinTransformer YOLO), Module(CBAM, DCN), Pruning (EagleEye, Network Slimming), Quantization (MQBench) and Deployment (TensorRT, ncnn) Compression Tool Box.

https://github.com/bestsongc/yolov5-multibackbone-compression

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.0%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

YOLOv5 Series Multi-backbone(TPH-YOLOv5, Ghostnet, ShuffleNetv2, Mobilenetv3Small, EfficientNetLite, PP-LCNet, SwinTransformer YOLO), Module(CBAM, DCN), Pruning (EagleEye, Network Slimming), Quantization (MQBench) and Deployment (TensorRT, ncnn) Compression Tool Box.

Basic Info
  • Host: GitHub
  • Owner: Bestsongc
  • Default Branch: main
  • Homepage:
  • Size: 2.77 MB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Fork of Gumpest/YOLOv5-Multibackbone-Compression
Created almost 3 years ago · Last pushed about 4 years ago

https://github.com/Bestsongc/YOLOv5-Multibackbone-Compression/blob/main/

# YOLOv5-Compression

![](https://img.shields.io/badge/Update-News-blue.svg?style=plastic)

2021.10.30 TPH-YOLOv5

2021.10.31 backboneGhostnet

2021.11.02 backboneShufflenetv2

2021.11.05 backboneMobilenetv3Small

2021.11.10 EagleEyeYOLOv5

2021.11.14 MQBenchYOLOv5

2021.11.16 backboneEfficientNetLite-0

2021.11.26 backbonePP-LCNet-1x

2021.12.12 SwinTrans-YOLOv5C3STR

2021.12.15 SlimmingYOLOv5

## Requirements

```shell
pip install -r requirements.txt
```

## Multi-Backbone Substitution for YOLOs

### 1Base Model

Train on Visdrone DataSet (*Input size is 608*)

| No.  | Model   | mAP  | mAP@50 | Parameters(M) | GFLOPs |
| ---- | ------- | ---- | ------ | ------------- | ------ |
| 1    | YOLOv5n | 13.0 | 26.20  | 1.78          | 4.2    |
| 2    | YOLOv5s | 18.4 | 34.00  | 7.05          | 15.9   |
| 3    | YOLOv5m | 21.6 | 37.80  | 20.91         | 48.2   |
| 4    | YOLOv5l | 23.2 | 39.70  | 46.19         | 108.1  |
| 5    | YOLOv5x | 24.3 | 40.80  | 86.28         | 204.4  |

### 2Higher Precision Model

#### ATPH-YOLOv5 ![](https://img.shields.io/badge/Model-BeiHangUni-yellowgreen.svg?style=plastic)

Train on Visdrone DataSet (*6-7 size is 6408 size is 1536*)

| No.  | Model          | mAP  | mAP@50 | Parameters(M) | GFLOPs |
| ---- | -------------- | ---- | ------ | ------------- | ------ |
| 6    | YOLOv5xP2      | 30.0 | 49.29  | 90.96         | 314.2  |
| 7    | YOLOv5xP2 CBAM | 30.1 | 49.40  | 91.31         | 315.1  |
| 8    | YOLOv5x-TPH    | 40.7 | 63.00  | 112.97        | 270.8  |

###### Usage

```shell
nohup python train.py --data VisDrone.yaml --weights yolov5n.pt --cfg models/yolov5n.yaml --epochs 300 --batch-size 8 --img 608 --device 0,1 --sync-bn >> yolov5n.txt &
```

###### Composition

**P2 HeadCBAMTPHBiFPNSPP**

TPH-YOLOv5

1TransBlockYOLOYOLOv5m

2YOLOv5x11419CBAM2P21283SPPSPPkernelP4CBAM5backboneTransBlock6BiFPNneck

3Loss



| box  | cls  | obj  | acc       |
| ---- | ---- | ---- | --------- |
| 0.05 | 0.5  | 1.0  | 37.90     |
| 0.05 | 0.3  | 0.7  | **38.00** |
| 0.05 | 0.2  | 0.4  | 37.5      |

loss

#### BSwinTrans-YOLOv5![](https://img.shields.io/badge/Model-Microsoft-yellow.svg?style=plastic)

```shell
pip install timm
```

###### Usage

```shell
python train.py --data VisDrone.yaml --weights yolov5x.pt --cfg models/accModels/yolov5xP2CBAM-Swin-BiFPN-SPP.yaml --hyp data/hyps/hyp.visdrone.yaml --epochs 60 --batch-size 4 --img 1536 --nohalf
```

1Window size***7******8***

2create_maskinitforward

3window sizePadding

*debugpaddingcv2img_size*

4forwardreshape

5C3STRhalf*--nohalf*

### 3Slighter Model

Train on Visdrone DataSet (*1 size is 6082-6 size is 640*)

| No   | Model                     | mAP       | mAP@50 | Parameters(M) | GFLOPs   | TrainCost(h) | Memory Cost(G) | PT File                                                      | FPS@CPU |
| ---- | ------------------------- | --------- | ------ | ------------- | -------- | ------------ | -------------- | ------------------------------------------------------------ | ------- |
| 1    | YOLOv5l                   | 23.2      | 39.7   | 46.19         | 108.1    |              |                |                                                              |         |
| 2    | YOLOv5l-GhostNet          | 18.4      | 33.8   | 24.27         | 42.4     | 27.44        | 4.97           | [PekingUni Cloud](https://disk.pku.edu.cn:443/link/35BD905E65DE091E2A58316B20BBE775) |         |
| 3    | YOLOv5l-ShuffleNetV2      | 16.48     | 31.1   | 21.27         | 40.5     | 10.98        | 2.41           | [PekingUni Cloud](https://disk.pku.edu.cn:443/link/A5ED89B7B190FCF1C8187A0A8AF20C4F) |         |
| 4    | YOLOv5l-MobileNetv3Small  | 16.55     | 31.2   | **20.38**     | **38.4** | **10.19**    | 5.30           | [PekingUni Cloud](https://disk.pku.edu.cn:443/link/EE375ED30AAD3F2B3FA5055DD6F4964C) |         |
| 5    | YOLOv5l-EfficientNetLite0 | **19.12** | **35** | 23.01         | 43.9     | 13.94        | 2.04           | [PekingUni Cloud](https://disk.pku.edu.cn:443/link/45E65A080C4574036EE274B7BD83B7EA) |         |
| 6    | YOLOv5l-PP-LCNet          | 17.63     | 32.8   | 21.64         | 41.7     | 18.52        | **1.66**       | [PekingUni Cloud](https://disk.pku.edu.cn:443/link/7EBE07BA6D7985C7053BF0A8F2591464) |         |

#### AGhostNet-YOLOv5 ![](https://img.shields.io/badge/Model-HuaWei-orange.svg?style=plastic)

GhostNet

1DWkernel_size3

2neckheadYOLOv5l

3expand

#### BShuffleNetV2-YOLOv5 ![](https://img.shields.io/badge/Model-Megvii-orange.svg?style=plastic)

Shffulenet

1Focus Layerslice

2C3 LeyerC3 LayerG1G3

3

#### CMobileNetv3Small-YOLOv5 ![](https://img.shields.io/badge/Model-Google-orange.svg?style=plastic)

Mobilenetv3s

1Hard-SwishSE

2NeckheadYOLOv5l

3expand

#### DEfficientNetLite0-YOLOv5 ![](https://img.shields.io/badge/Model-Google-orange.svg?style=plastic)


efficientlite

1Lite0SE

2dropout_connect_rate(idx_stage)

3*6expand

#### EPP-LCNet-YOLOv5  ![](https://img.shields.io/badge/Model-Baidu-orange.svg?style=plastic)


PP-LCNet


1PP-LCNet-1xSE5*5

2SeBlock1/16

3

## Pruning for YOLOs

| Model                | mAP  | mAP@50 | Parameters(M) | GFLOPs | FPS@CPU |
| -------------------- | ---- | ------ | ------------- | ------ | ------- |
| YOLOv5s              | 18.4 | 34     | 7.05          | 15.9   |         |
| YOLOv5n              | 13   | 26.2   | 1.78          | 4.2    |         |
| YOLOv5s-EagleEye@0.6 | 14.3 | 27.9   | 4.59          | 9.6    |         |

### 1Prune Strategy

1YOLOv5ConvC3SPP(F)

- Conv
- C3cv2cv3
- C3bottleneckcv1

2outchannel = 8*n

3ShortCutconcat

### 2Prune Tools

#### 1EagleEye

[EagleEye: Fast Sub-net Evaluation for Efficient Neural Network Pruning](https://arxiv.org/abs/2007.02491)

BN

![eagleeye](https://github.com/Cydia2018/YOLOv5-Multibackbone-Compression/blob/main/img/eagleeye.png)

##### Usage

1. 

```shell
python train.py --data data/VisDrone.yaml --imgsz 640 --weights yolov5s.pt --cfg models/prunModels/yolov5s-pruning.yaml --device 0
```

/prunModels/yolov5s-pruning.yamlv6

2. 

```shell
python pruneEagleEye.py --weights path_to_trained_yolov5_model --cfg models/prunModels/yolov5s-pruning.yaml --data data/VisDrone.yaml --path path_to_pruned_yolov5_yaml --max_iter maximum number of arch search --remain_ratio the whole FLOPs remain ratio --delta 0.02
```

3. 

```shell
python train.py --data data/VisDrone.yaml --imgsz 640 --weights path_to_Eaglepruned_yolov5_model --cfg path_to_pruned_yolov5_yaml --device 0
```

#### 2Network Slimming

[Learning Efficient Convolutional Networks through Network Slimming](https://openaccess.thecvf.com/content_ICCV_2017/papers/Liu_Learning_Efficient_Convolutional_ICCV_2017_paper.pdf)

##### Usage

1. BatchNorm Layer \gamma 

```shell
python train.py --data data/VisDrone.yaml --imgsz 640 --weights yolov5s.pt --cfg models/prunModels/yolov5s-pruning.yaml --device 0 --sparse
```

/prunModels/yolov5s-pruning.yamlv6

2. BatchNorm Layer

```shell
python pruneSlim.py --weights path_to_sparsed_yolov5_model --cfg models/prunModels/yolov5s-pruning.yaml --data data/VisDrone.yaml --path path_to_pruned_yolov5_yaml --global_percent 0.6 --device 3
```

3. 

```shell
python train.py --data data/VisDrone.yaml --imgsz 640 --weights path_to_Slimpruned_yolov5_model --cfg path_to_pruned_yolov5_yaml --device 0
```

## Quantize Aware Training for YOLOs

 MQBenchQAT

### Requirements

- PyTorch == 1.8.1

### Install MQBench Lib ![](https://img.shields.io/badge/Tec-Sensetime-brightgreen.svg?style=plastic)

MQBench0.0.2

```shell
git clone https://github.com/ZLkanyo009/MQBench.git
cd MQBench
python setup.py build
python setup.py install
```

### Usage



```shell
python train.py --data VisDrone.yaml --weights yolov5n.pt --cfg models/yolov5n.yaml --epochs 300 --batch-size 8 --img 608 --nosave --device 0,1 --sync-bn --quantize --BackendType NNIE
```

## Deploy
TensorRTNCNN[YOLOv5-Multibackbone-Compression/deploy](https://github.com/Gumpest/YOLOv5-Multibackbone-Compression/blob/main/deploy)

## To do

- [x] Multibackbone: MobileNetV3-small
- [x] Multibackbone: ShuffleNetV2
- [x] Multibackbone: GhostNet
- [x] Multibackbone: EfficientNet-Lite0
- [x] Multibackbone: PP-LCNet
- [x] Multibackbone: TPH-YOLOv5
- [x] Module: SwinTransC3STR
- [ ] Module: Deformable Convolution
- [x] Pruner: Network Slimming
- [x] Pruner: EagleEye
- [ ] Pruner: OneShot (L1, L2, FPGM), ADMM, NetAdapt, Gradual, End2End
- [x] Quantization: MQBench
- [ ] Knowledge Distillation

## Acknowledge

TPH-YOLOv5Xingkui Zhu 

[cv516Buaa/tph-yolov5 (github.com)](https://github.com/cv516Buaa/tph-yolov5)

[ZJU-lishuang/yolov5_prune: yolov5v2,v3,v4,v6yolov5 (github.com)](https://github.com/ZJU-lishuang/yolov5_prune)

Owner

  • Name: Bestsongc
  • Login: Bestsongc
  • Kind: user

GitHub Events

Total
Last Year