Giter Site home page Giter Site logo

sharpiless / yolov5-distillation-train-inference Goto Github PK

View Code? Open in Web Editor NEW
201.0 2.0 32.0 2.42 MB

Yolov5 distillation training | Yolov5知识蒸馏训练,支持训练自己的数据

License: GNU General Public License v3.0

Dockerfile 0.70% Python 91.25% Shell 3.60% Jupyter Notebook 4.45%
yolov5 distillation object-detection model-compression konwledge-distillation

yolov5-distillation-train-inference's Introduction

代码地址:

https://github.com/Sharpiless/Yolov5-distillation-train-inference

最新版本:

请移步:https://github.com/Sharpiless/yolov5-distillation-5.0

教师模型权重:

链接:https://pan.baidu.com/s/13gq5QwCrRNdRXWzSYUeJIw

提取码:4ppv

蒸馏训练:

python train_distill.py --weights yolov5s.pt \
    --teacher weights/yolov5l_voc.pt --distill_ratio 0.001 \
    --teacher-cfg model/yolov5l.yaml --data data/voc.yaml \
    --epochs 30 --batch-size 16

训练参数:

--weights:预训练模型

--teacher:教师模型权重

--distill-ratio:蒸馏损失权重

--with-gt-loss:是否同时使用ground truth

--soft-loss:是否使用KL散度作为蒸馏的类别损失(缺省使用L2-logits损失)

--full-output-loss:是否使用《Object detection at 200 Frames Per Second》中的损失

这篇文章分别对这几个损失函数做出改进,具体思路为只有当teacher network的objectness value高时,才学习bounding box坐标和class probabilities。

准备数据集:

默认会启用 data/voc.yaml 自动下载VOC数据集进行训练

或者手动运行 data/scripts/get_voc2007.sh 下载

如需修改成自己的数据集,则只需要修改yaml路径即可

实验结果:

数据集:

VOC2007(补充的无标签数据使用VOC2012)

GPU:2080Ti*1

Batch Size:16

Epoches:30

Baseline:Yolov5s

Teacher model:Yolov5l(mAP 0.5:0.95 = 0.541)

这里假设VOC2012中新增加的数据为无标签数据(2k张)。

教师模型 训练方法 蒸馏损失 P R mAP50
正常训练 不使用 0.7756 0.7115 0.7609
Yolov5l output based l2 0.7585 0.7198 0.7644
Yolov5l output based KL 0.7417 0.7207 0.7536
Yolov5m output based l2 0.7682 0.7436 0.7976
Yolov5m output based KL 0.7731 0.7313 0.7931

训练结果

参数和细节正在完善,支持KL散度、L2 logits损失和Sigmoid蒸馏损失等

待做事项:

  • [√] 修改logist输出作为蒸馏损失输入
  • [√] 完善代码结构和相关参数设定
  • [×] 查找为何蒸馏损失不起作用(或者收敛慢)的原因
  • [×] 完善相关实验并测试精度
  • [√] 修改dataloader加快训练速度
  • [√] 修改teacher model的批量推理加快训练速度

可能存在的问题:

  • 1.训练轮数太少没收敛,可能蒸馏训练收敛满最终结果高
  • 2.教师模型是Yolov5l在VOC训练30轮得到的(mAP 0.5:0.95 = 0.541),质量比标注较差影响蒸馏训练的结果
  • 3.可调整的参数还有很多(教师模型的检测、IOU阈值,蒸馏损失种类,蒸馏损失比率等)

我的公众号:

在这里插入图片描述

yolov5-distillation-train-inference's People

Contributors

sharpiless 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

yolov5-distillation-train-inference's Issues

CenterNet 知识蒸馏

  • 作者您好,我(蒸馏小白)想针对CenterNet网络进行知识蒸馏,大概的实现思路是什么样子的,

Arguments --soft-loss 和 --KL-loss

In the example notebook there is this line:

!python train_distill.py --soft-loss --KL-loss --full-output-loss --with-gt-loss

However the arguments --soft-loss--KL-loss don't exist in train_distill.py. Maybe outdated?

AttributeError: Can't get attribute 'SPPF' on <module 'models.common' from '/content/Yolov5-distillation-train-inference/models/common.py'>

how to fix this ? plz help

Traceback (most recent call last):
File "train_distill.py", line 602, in
train(hyp, opt, device, tb_writer)
File "train_distill.py", line 71, in train
'.pt') and os.path.isfile(weights) else None
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 882, in _load
result = unpickler.load()
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'SPPF' on <module 'models.common' from '/content/Yolov5-distillation-train-inference/models/common.py'>

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.