Giter Club home page Giter Club logo

yolo-multi-backbones-attention's Introduction

Introduction

This Repository includes YOLOv3 with some lightweight backbones (ShuffleNetV2, GhostNet, VoVNet), some computer vision attention mechanism (SE Block, CBAM Block, ECA Block), pruning,quantization and distillation for GhostNet.

Important Update

2020.6.1
(1) The best lightweight model——HuaWei GhostNet has been added as the YOLOv3 backbone! It is better than ShuffleNetV2. The result for visdrone dataset is as following.
(2) Add Dorefa quantization method for arbitrary bit quantization! The result for visdrone dataset is as following.
(3) And I delete the ShuffleNet and the attention mechanism.
2020.6.24
(1) Add pruning according to NetworkSlimming.
(2) Add distillation for higher mAP after pruning.
(3) Add Imagenet pretraining model for GhostNet.
2020.9.26
(1) Add VoVNet as the backbone. The result is excellent.

Model Params FPS mAP
GhostNet+YOLOv3 23.49M 62.5 35.1
Pruned Model+Distillation 5.81M 76.9 34.3
Pruned Model+INT8 5.81M 75.1 34
YOLOv5s 7.27M - 32.7
YOLOv5x 88.5M - 41.8
VoVNet 42.8M 28.9 42.7

Attention : Single GPU will be better
If you need previous attention model or have any question, you can add my WeChat: AutrefoisLethe

Environment

  • python 3.7
  • pytorch >= 1.1.0
  • opencv-python

Datasets

Usage

  1. Download the datasets, place them in the data directory
  2. Train the models by using following command (change the model structure by changing the cfg file)
  python3 train.py --data data/visdrone.data --batch-size 16 --cfg cfg/ghost-yolov3-visdrone.cfg --img-size 640
  1. Detect objects using the trained model (place the pictures or videos in the samples directory)
  python3 detect.py --cfg cfg/ghostnet-yolov3-visdrone.cfg --weights weights/best.pt --data data/visdrone.data
  1. Results:
    most
    car
    airplane

Pruning and Quantization

Pruning

First of all, execute sparse training.

python3 train.py --data data/visdrone.data --batch-size 4 --cfg cfg/ghost-yolov3-visdrone.cfg --img-size 640 --epochs 300  --device 3 -sr --s 0.0001

Then change cfg and weights in normal_prune.py then use following command

python normal_prune.py

After obtaining pruned.cfg and corresponding weights file, you can fine-tune the pruned model via following command

python3 train.py --data data/visdrone.data --batch-size 4 --cfg pruned.cfg --img-size 640 --epochs 300  --device 3 --weights weights/xxx.weighs

Quantization

If you want to quantize certain convolutional layer, you can just change the [convolutional] to [quan_convolutional] in cfg file. Then use following command

  python3 train.py --data data/visdrone.data --batch-size 16 --cfg cfg/ghostnet-yolov3-visdrone.cfg --img-size 640

Experiment Result for Changing YOLOv3 Backbone

ShuffleNetV2 + Two Scales Detection(YOLO Detector)

Using Oxfordhand datasets

Model Params Model Size mAP
ShuffleNetV2 1x 3.57M 13.89MB 51.2
ShuffleNetV2 1.5x 5.07M 19.55MB 56.4
YOLOv3-tiny 8.67M 33.1MB 60.3

Using Visdrone datasets(Incomplete training)

Model Params Model Size mAP
ShuffleNetV2 1x 3.59M 13.99MB 10.2
ShuffleNetV2 1.5x 5.09M 19.63MB 11
YOLOv3-tiny 8.69M 33.9MB 3.3

Experiment Result for Attention Mechanism

Based on YOLOv3-tiny

SE Block paper : https://arxiv.org/abs/1709.01507
CBAM Block paper : https://arxiv.org/abs/1807.06521
ECA Block paper : https://arxiv.org/abs/1910.03151

Model Params mAP
YOLOv3-tiny 8.67M 60.3
YOLOv3-tiny + SE 8.933M 62.3
YOLOv3-tiny + CBAM 8.81M 62.7
YOLOv3-tiny + ECA 8.67M 62.6

TODO

  • ShuffleNetV2 backbone
  • HuaWei GhostNet backbone
  • ImageNet pretraining
  • COCO datasets training
  • Other detection strategies
  • Other pruning strategies

yolo-multi-backbones-attention's People

Contributors

halotrouvaille avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yolo-multi-backbones-attention's Issues

train.py

Traceback (most recent call last):
File "train.py", line 467, in
opt.cfg = list(glob.iglob('./**/' + opt.cfg, recursive=True))[0] # find file
IndexError: list index out of range
Why?

visdrone训练参数

您好,您给出的visdrone数据集的训练结果就是您代码中的默认参数的结果吗

关于cfg

你好,关于cfg文件我有个小问题:我看到原始yolov3的cfg文件中第一个卷积核的数量是64,而你的ghostnet的cfg文件中第一个卷积核数量是16,而且基本上每一个卷积核的数量都比原始的要少,这是为什么呢?

cfg文件的问题

在吗作者 有一些问题可否问下。cfg文件中的内容完整吗?

“activation=linear”

“activation=linear” appears in cfg files, but there is no description in “models.py”. Can you tell me what to do?

量化问题

您好, 代码里量化时没有对BN层做处理, 参数仍然是fp32, 这个在部署时要怎么处理呢?

VoVNet

骨干网络为VoVNet的cfg文件以及对应的model.py网络解析内容大佬有吗??

问题请教

你换了ShuffleUnit之后,除了模型方面创建方面,其他地方有没有修改,我的微信17868380981,我有个疑问想和你讨论。

Error while training with a custom dataset

Hello I am trying to train with a custom dataset and I am facing the following issue:

image

All images of my custom dataset is 448x320. I already made the changes in image size parameter, but this error still showing.

Could someone help me with this issue?

#数据集

你好作者,想问下有没有bdk100的数据集网盘呀,分享的链接取消了,感谢!!

RuntimeError: Sizes of tensors must match except in dimension 2. Got 40 and 48

Thank you for your great work.An error occurred while I was running the code.
python3 train.py --data data/oxfordhand.data --batch-size 1 --cfg cfg/yolov3-tiny-hand-se.cfg --epochs 100 -sr --s 0.001 --img-size 640 --weights ''
......
RuntimeError: Sizes of tensors must match except in dimension 2. Got 40 and 48
Can you give me some advice to solve this problem?

where is cbam?

I only saw se,but no cbam,please tell me where is it,thank you!

量化问题

你好,量化前后为什么保存的模型大小都是180MB,量化并没有减小模型的大小?

Train erro

您好,我在用yolov3-tiny训练自己的数据集时出现了以下错误,能帮忙看下么
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 40 and 48 in dimension 2 at /pytorch/aten/src/THC/generic/THCTensorMath.cu:71

Parameters for Ghostnet + YoloV3

Hi,
You have mentioned the number of parameters for Ghostnet + Yolov3 to be 23.49M. I wanted to confirm if it is correct or it should be 2.349M? The number of parameters seem to be too larger than the other models.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.