YOLOv5 Series Multi-backbone, Pruning and quantization Compression Tool Box.

Overview

YOLOv5-Compression

Update News

Requirements

环境安装

pip install -r requirements.txt

Evaluation metric

Visdrone

Model mAP mAP@50 Parameters(M) GFLOPs FPS@CPU
YOLOv5n 13 26.2 1.78 4.2
YOLOv5s 18.4 34 7.05 15.9
YOLOv5m 21.6 37.8 20.91 48.2
YOLOv5l 23.2 39.7 46.19 108.1
YOLOv5x 24.3 40.8 86.28 204.4

yolov5n

nohup 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 >> yolov5n.txt &

To do

  • Multibackbone: mobilenetv3
  • Multibackbone: shufflenetv2
  • Multibackbone: ghostnet
  • Multibackbone: TPH-YOLOv5
  • Pruning: Network slimming
  • Quantization: 4bit QAT
  • Knowledge Distillation
Comments
  • 自定义网络剪枝问题请教

    自定义网络剪枝问题请教

    作者现有的剪枝,经过测试非常有效,现有对网络修改后,再运行剪枝失败,请指教:# parameters nc: 1 # number of classes depth_multiple: 0.33 # model depth multiple width_multiple: 0.50 # layer channel multiple

    anchors

    anchors:

    • [4,4, 5,5, 5,5] # P2/4
    • [5,5, 5,5, 6,6] # P3/8
    • [6,6, 7,7, 8,8] # P4/16 #- [116,90, 156,198, 373,326] # P5/16 #- 4,4, 5,5, 5,5, 5,5, 5,5, 6,6, 6,6, 7,7, 8,8

    YOLOv5 backbone

    backbone:

    [from, number, module, args]

    [from, number, module, args]

    [ [ -1, 1, Conv, [ 64, 6, 2, 2, 1, True, 1.0 ] ], # 0-P1/2 [ -1, 1, Conv, [ 128, 3, 2, None, 1, True, 1.0 ] ], # 1-P2/4 [ -1, 3, C3, [ 128, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0 ], 1.0 ] ], [ -1, 1, Conv, [ 256, 3, 2, None, 1, True, 1.0 ] ], # 3-P3/8 [ -1, 6, C3, [ 256, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ], 1.0 ] ], [ -1, 1, Conv, [ 512, 3, 2, None, 1, True, 1.0 ] ], # 5-P4/16 [ -1, 9, C3, [ 512, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ], 1.0 ] ],

    [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 去掉32倍特征图输出

    [ -1, 3, C3, [ 512, True, 1, [ 0.5, 0.5 ], [ 1.0, 1.0, 1.0 ], 1.0 ] ],
    [ -1, 1, SPPF, [ 512, 5, 0.5 ] ],  # 9
    

    ]

    YOLOv5 v6.0 head

    head: [[-1, 1, Conv, [512, 1, 1, None, 1, True, 1.0]], [-1, 1, nn.Upsample, [None, 2, 'nearest']], [[-1, 4], 1, Concat, [1]], # cat backbone P3 [-1, 3, C3, [512, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 17 (P3/8-small)

    [ -1, 1, Conv, [256, 1, 1, None, 1, True, 1.0]], [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ], [ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2 160*160 [ -1, 3, C3, [256, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 16 (P2/4-small)

    [-1, 1, Conv, [256, 3, 2, None, 1, True, 1.0]], [[-1, 13], 1, Concat, [1]], # cat head P2 [-1, 3, C3, [256, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 20 (P3/16-medium)

    [-1, 1, Conv, [256, 3, 2, None, 1, True, 1.0]], [[-1, 9], 1, Concat, [1]], # cat head P4 [-1, 3, C3, [512, False, 1, [0.5, 0.5], [1.0, 1.0, 1.0], 1.0]], # 22 (P4/16-large)

    [[16, 19, 22], 1, Detect, [nc, anchors]], # Detect(P2, P3, P4) ]

    opened by tonyskypc 4
  • yolov5lEfficientLite出错

    yolov5lEfficientLite出错

    运行EfficientLite 时出错 错误信息: Traceback (most recent call last): File "E://YOLOv5-Multibackbone-Compression-main/train.py", line 656, in main(opt) File "E:/YOLOv5-Multibackbone-Compression-main/train.py", line 553, in main train(opt.hyp, opt, device, callbacks) File "E:/cYOLOv5-Multibackbone-Compression-main/train.py", line 125, in train model = Model(cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create File "E:\YOLOv5-Multibackbone-Compression-main\models\yolo.py", line 103, in init self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch], pruning=pruning) # model, savelist File "E:\YOLOv5-Multibackbone-Compression-main\models\yolo.py", line 305, in parse_model m_ = nn.Sequential(*[m(*args) for _ in range(n)]) if n > 1 else m(*args) # module TypeError: init() missing 1 required positional argument: 'drop_connect_rate'

    opened by yyy8439 4
  • yolov5-TPH运行错误

    yolov5-TPH运行错误

    您好,我运行yolov5n,s,m,l都没问题,但是运行yolov5x-TPH,yolov5m-TPH-std,yolov5x时出现错误如下: File "/wangjun/TPH_yolo/train.py", line 656, in main(opt) File "/wangjun/TPH_yolo/train.py", line 553, in main train(opt.hyp, opt, device, callbacks) File "/wangjun/TPH_yolo/train.py", line 132, in train model = Model(cfg, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create File "/wangjun/TPH_yolo/models/yolo.py", line 103, in init self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch], pruning=pruning) # model, savelist File "/wangjun/TPH_yolo/models/yolo.py", line 305, in parse_model m_ = nn.Sequential(*[m(args) for _ in range(n)]) if n > 1 else m(args) # module File "/wangjun/TPH_yolo/models/common.py", line 419, in init self.m = nn.Sequential([Bottleneck(c1_, c1_, shortcut, g, e=rate[i]) for i in range(n)]) File "/wangjun/TPH_yolo/models/common.py", line 419, in self.m = nn.Sequential([Bottleneck(c1_, c1_, shortcut, g, e=rate[i]) for i in range(n)]) IndexError: list index out of range

    opened by wj51 4
  • 大佬如果改动使用MBConvBlock的se模块呢 设置True,会报错

    大佬如果改动使用MBConvBlock的se模块呢 设置True,会报错

    File "F:/999yolo/YOLOv5-Multibackbone-Compression-main/models/yolo.py", line 331, in model = Model(opt.cfg).to(device) File "F:/999yolo/YOLOv5-Multibackbone-Compression-main/models/yolo.py", line 112, in init m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))]) # forward File "F:/999yolo/YOLOv5-Multibackbone-Compression-main/models/yolo.py", line 128, in forward return self._forward_once(x, profile, visualize) # single-scale inference, train File "F:/999yolo/YOLOv5-Multibackbone-Compression-main/models/yolo.py", line 152, in _forward_once x = m(x) # run File "D:\Anaconda3\envs\y55\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "F:\999yolo\YOLOv5-Multibackbone-Compression-main\models\common.py", line 142, in forward x_squeezed = nn.AdaptiveAvgPool2d(x, 1) TypeError: init() takes 2 positional arguments but 3 were given

    bug 
    opened by ahhhxxx 2
  • 论文中提到的TPH的疑问

    论文中提到的TPH的疑问

    论文中提到 Based on YOLOv5, we only apply transformer encoder blocks in the head part to form Transformer Prediction Head (TPH) and the end of backbone.

    但是我看TPH更多是用在了neck层上面,backbones上面增加了一个,而head上面是没有增加TPH。head层上面改变更多的是增加了一个头。

    不知道我理解的是否有问题。 谢谢了

    opened by CloudRobot 1
  • 运行 YOLOv5s模型在NNIE量化训练下错误!

    运行 YOLOv5s模型在NNIE量化训练下错误!

    您好!

    我这边最近尝试复现您开源的基于MQBench下的NNIE量化方式,为了解决在海思芯片上算法量化精度掉点的问题。

    然后,我这边复现的时候遇到了如下问题:

    1.common.py中C3模块的问题,导致报错,修改为官方v6.0版本的C3模块解决。

    2.AttributeError: 'GraphModule' object has no attribute 'module' error

    暂未解决,我看到其他开发者也遇到了类似问题,如下:

    https://github.com/Gumpest/YOLOv5-Multibackbone-Compression/issues/83

    能帮忙指导一下吗?谢谢~

    opened by tensorflowt 0
  • 运行pruneSlim.py时报错IndexError: list index out of range

    运行pruneSlim.py时报错IndexError: list index out of range

    image 请问怎么解决?Traceback (most recent call last): File "pruneEagleEye.py", line 127, in rand_prune_and_eval(model,ignore_idx,opt) File "pruneEagleEye.py", line 59, in rand_prune_and_eval pruned_yaml = update_yaml(pruned_yaml, model, ignore_conv_idx, maskconvdict, opt) File "/hy-nas/yolov5-multibackbone/utils/prune_utils.py", line 263, in update_yaml update_yaml_loop(pruned_yaml,name,maskdict) File "/hy-nas/yolov5-multibackbone/utils/prune_utils.py", line 247, in update_yaml_loop args[-3][1] = 0.5 * maskconvdict[named_m_cv2_conv].sum().item() / (c2*0.5) IndexError: list index out of range

    opened by dtde 0
  • 你好,我尝试复现您的yolov5xP2CBAM-TPH-BiFPN-SPP.yaml模型文件的结果,但是最终精度和您复现的效果相差比较大。

    你好,我尝试复现您的yolov5xP2CBAM-TPH-BiFPN-SPP.yaml模型文件的结果,但是最终精度和您复现的效果相差比较大。

    以下是我的训练命令行: nohup python train.py --cfg yolov5xP2CBAM-TPH-BiFPN-SPP.yaml --weights 'weights/yolov5x.pt' --img 640 --data myVisDrone.yaml --hyp data/hyps/hyp.visdrone.yaml --epochs 81 --device 0,1 --batch-size 2 --name '5x_tph_ori_640_526' &

    然后我训练了81轮 我的metrics/mAP_0.5:0.95只有0.024101 以下是我的train_batch.jpg image

    这是我的数据集文件

    Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]

    #path: ../datasets/VisDrone # dataset root dir #path: /home/ff/WangZF/datasets/visdrone # dataset root dir train: /home/ff/WangZF/datasets/visdrone/YOLOFormat/train/images # train images (relative to 'path') 6471 images val: /home/ff/WangZF/datasets/visdrone/YOLOFormat/val/images # val images (relative to 'path') 548 images test: /home/ff/WangZF/datasets/visdrone/YOLOFormat/val/images # test images (optional) 1610 images

    Classes

    nc: 10 # number of classes names: [ 'pedestrian', 'people', 'bicycle', 'car', 'van', 'truck', 'tricycle', 'awning-tricycle', 'bus', 'motor' ] 我不知道是哪里出错了

    opened by wong1998 1
Owner
ZhangYuan
神经形态计算
ZhangYuan
LIAO Shuiying 6 Dec 1, 2022
Multi-task yolov5 with detection and segmentation based on yolov5

YOLOv5DS Multi-task yolov5 with detection and segmentation based on yolov5(branch v6.0) decoupled head anchor free segmentation head README中文 Ablation

null 150 Dec 30, 2022
DiffQ performs differentiable quantization using pseudo quantization noise. It can automatically tune the number of bits used per weight or group of weights, in order to achieve a given trade-off between model size and accuracy.

Differentiable Model Compression via Pseudo Quantization Noise DiffQ performs differentiable quantization using pseudo quantization noise. It can auto

Facebook Research 145 Dec 30, 2022
Quantization library for PyTorch. Support low-precision and mixed-precision quantization, with hardware implementation through TVM.

HAWQ: Hessian AWare Quantization HAWQ is an advanced quantization library written for PyTorch. HAWQ enables low-precision and mixed-precision uniform

Zhen Dong 293 Dec 30, 2022
Nonuniform-to-Uniform Quantization: Towards Accurate Quantization via Generalized Straight-Through Estimation. In CVPR 2022.

Nonuniform-to-Uniform Quantization This repository contains the training code of N2UQ introduced in our CVPR 2022 paper: "Nonuniform-to-Uniform Quanti

Zechun Liu 60 Dec 28, 2022
🍅🍅🍅YOLOv5-Lite: lighter, faster and easier to deploy. Evolved from yolov5 and the size of model is only 1.7M (int8) and 3.3M (fp16). It can reach 10+ FPS on the Raspberry Pi 4B when the input size is 320×320~

YOLOv5-Lite:lighter, faster and easier to deploy Perform a series of ablation experiments on yolov5 to make it lighter (smaller Flops, lower memory, a

pogg 1.5k Jan 5, 2023
An implementation of based on pytorch and mmcv

FisherPruning-Pytorch An implementation of <Group Fisher Pruning for Practical Network Compression> based on pytorch and mmcv Main Functions Pruning f

Peng Lu 15 Dec 17, 2022
Group Fisher Pruning for Practical Network Compression(ICML2021)

Group Fisher Pruning for Practical Network Compression (ICML2021) By Liyang Liu*, Shilong Zhang*, Zhanghui Kuang, Jing-Hao Xue, Aojun Zhou, Xinjiang W

Shilong Zhang 129 Dec 13, 2022
A Closer Look at Structured Pruning for Neural Network Compression

A Closer Look at Structured Pruning for Neural Network Compression Code used to reproduce experiments in https://arxiv.org/abs/1810.04622. To prune, w

Bayesian and Neural Systems Group 140 Dec 5, 2022
TPH-YOLOv5: Improved YOLOv5 Based on Transformer Prediction Head for Object Detection on Drone-Captured Scenarios

TPH-YOLOv5 This repo is the implementation of "TPH-YOLOv5: Improved YOLOv5 Based on Transformer Prediction Head for Object Detection on Drone-Captured

cv516Buaa 439 Dec 22, 2022
Yolov5-lite - Minimal PyTorch implementation of YOLOv5

Yolov5-Lite: Minimal YOLOv5 + Deep Sort Overview This repo is a shortened versio

Kadir Nar 57 Nov 28, 2022
An Image compression simulator that uses Source Extractor and Monte Carlo methods to examine the post compressive effects different compression algorithms have.

ImageCompressionSimulation An Image compression simulator that uses Source Extractor and Monte Carlo methods to examine the post compressive effects o

James Park 1 Dec 11, 2021
Revisiting Discriminator in GAN Compression: A Generator-discriminator Cooperative Compression Scheme (NeurIPS2021)

Revisiting Discriminator in GAN Compression: A Generator-discriminator Cooperative Compression Scheme (NeurIPS2021) Overview Prerequisites Linux Pytho

Shaojie Li 34 Mar 31, 2022
(ImageNet pretrained models) The official pytorch implemention of the TPAMI paper "Res2Net: A New Multi-scale Backbone Architecture"

Res2Net The official pytorch implemention of the paper "Res2Net: A New Multi-scale Backbone Architecture" Our paper is accepted by IEEE Transactions o

Res2Net Applications 928 Dec 29, 2022
Black-Box-Tuning - Black-Box Tuning for Language-Model-as-a-Service

Black-Box-Tuning Source code for paper "Black-Box Tuning for Language-Model-as-a

Tianxiang Sun 149 Jan 4, 2023
Time-series-deep-learning - Developing Deep learning LSTM, BiLSTM models, and NeuralProphet for multi-step time-series forecasting of stock price.

Stock Price Prediction Using Deep Learning Univariate Time Series Predicting stock price using historical data of a company using Neural networks for

Abdultawwab Safarji 7 Nov 27, 2022
yolox_backbone is a deep-learning library and is a collection of YOLOX Backbone models.

YOLOX-Backbone yolox-backbone is a deep-learning library and is a collection of YOLOX backbone models. Install pip install yolox-backbone Load a Pret

Yonghye Kwon 21 Dec 28, 2022
Pytorch Implementations of large number classical backbone CNNs, data enhancement, torch loss, attention, visualization and some common algorithms.

Torch-template-for-deep-learning Pytorch implementations of some **classical backbone CNNs, data enhancement, torch loss, attention, visualization and

Li Shengyan 270 Dec 31, 2022
A repo to show how to use custom dataset to train s2anet, and change backbone to resnext101

A repo to show how to use custom dataset to train s2anet, and change backbone to resnext101

jedibobo 3 Dec 28, 2022