Giter Club home page Giter Club logo

yolodet-pytorch's Introduction

简体中文 | English

YOLODet-PyTorch

YOLODet-PyTorch是端到端基于pytorch框架复现yolo最新算法的目标检测开发套件,旨在帮助开发者更快更好地完成检测模型的训练、精度速度优化到部署全流程。YOLODet-PyTorch以模块化的设计实现了多种主流YOLO目标检测算法,并且提供了丰富的数据增强、网络组件、损失函数等模块。

目前检测库下模型均要求使用PyTorch 1.5及以上版本或适当的develop版本。

内容

简介

特性:

  • 模型丰富:

    YOLODet提供了丰富的模型,涵盖最新YOLO检测算法的复现,包含YOLOv5、YOLOv4、PP-YOLO、YOLOv3等YOLO系列目标检测算法。

  • 高灵活度:

    YOLODet通过模块化设计来解耦各个组件,基于配置文件可以轻松地搭建各种检测模型。

支持的模型:

更多的Backone:

  • DarkNet
  • CSPDarkNet
  • ResNet
  • YOLOv5Darknet

数据增强方法:

  • Mosaic
  • MixUp
  • Resize
  • LetterBox
  • RandomCrop
  • RandomFlip
  • RandomHSV
  • RandomBlur
  • RandomNoise
  • RandomAffine
  • RandomTranslation
  • Normalize
  • ImageToTensor
  • 相关配置使用说明请参考【这里

损失函数支持:

  • bbox loss (IOU,GIOU,DIOU,CIOU)
  • confidence loss(YOLOv4,YOLOv5,PP-YOLO)
  • IOU_Aware_Loss(PP-YOLO)
  • FocalLoss

训练技巧支持:

  • 指数移动平均
  • 预热
  • 梯度剪切
  • 梯度累计更新
  • 多尺度训练
  • 学习率调整:Fixed,Step,Exp,Poly,Inv,Consine
  • Label Smooth
  • 强烈说明 通过实验对比发现YOLOv5的正负样本划分定义和损失函数定义,使得模型收敛速度较快,远超原yolo系列对正负样本的划分和损失定义。对于如果卡资源不充足,想在短时间内收敛模型,可采用yolov5的正负样本划分和损失函数定义,相关参数为yolo_loss_type=yolov5
  • 额外补充 YOLOv5对于正样本的定义:在不同尺度下只要真框和给定锚框的的比值在4倍以内,该锚框即可负责预测该真值框。并根据gx,gy在grid中心点位置的偏移量会额外新增两个grid坐标来预测。通过这一系列操作,增加了正样本数量,加速模型收敛速度。而YOLO原系列对于真框,在不同尺度下只有在该尺度下IOU交并集最大的锚框负责预测该真框,其他锚框不负责,所以由于较少的正样本量,模型收敛速度较慢。

扩展特性:

  • Group Norm
  • Modulated Deformable Convolution
  • Focus
  • Spatial Pyramid Pooling
  • FPN-PAN
  • coord conv
  • drop block
  • SAM

代码结构说明

yolodet-pytorch
├──cfg              #模型配置文件所在目录(yolov5,yolov4等)
├──tools            #工具包,包含训练代码,测试代码和推断代码入口。
├──yolodet          #YOLO检测框架核心代码库
│  ├──apis          #提供检测框架的训练,测试和推断和模型保存的接口
│  ├──dataset       #包含DateSet,DateLoader和数据增强等通用方法
│  ├──models        #YOLO检测框架的核心组件集结地
│  │  ├──detectors  #所有类型检测器集结地
│  │  ├──backbones  #所有骨干网络集结地
│  │  ├──necks      #所有necks集结地
│  │  ├──heads      #heads集结地
│  │  ├──loss       #所有损失函数集结地
│  │  ├──hooks      #hooks集结地(学习率调整,模型保存,训练日志,权重更新等)
│  │  ├──utils      #所有工具方法集结地

安装说明

安装和数据集准备请参考 INSTALL.md

快速开始

请参阅 GETTING_STARTED.md 了解YOLODet的基本用法。

预训练模型

查看预训练模型请点击【这里

重要说明

由于该检测框架为个人闲暇之余,处于对深度学习的热爱,自己单独编写完成,也由于自己囊中羞涩,没有充足的显卡资源,提供的MSCOCO大型数据集的预训练模型为未完整训练的模型,后面会陆陆续续提供完整版的预训练模型,敬请大家期待。对于小型数据集本人已经测试和验证过,并在实际项目中使用过该框架训练的模型,没有问题,精度和速度都能保证。

鸣谢

如何贡献代码

欢迎你为YOLODet提供代码,也十分感谢你的反馈。本人将不断完善和改进这个基于PyTorch实现的YOLO全系列的目标检测框架,并希望更多志同道合的爱好者和从业者能参与进来,共同维护这个项目。 如有对此感兴趣的同学,可联系我的gmail邮箱:[email protected],期待与你一起完善和进步。

yolodet-pytorch's People

Contributors

wuzhihao7788 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

yolodet-pytorch's Issues

Tuple Error when Data Loading

Traceback (most recent call last):
  File "tools/train.py", line 144, in <module>
    main()
  File "tools/train.py", line 140, in main
    train_detector(model,datasets,cfg,validate=args.validate,timestamp=timestamp,meta=meta)
  File "/home/wenchi/projects/yolodet-pytorch-2/yolodet/apis/train.py", line 161, in train_detector
    runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
  File "/home/wenchi/projects/yolodet-pytorch-2/yolodet/apis/runner.py", line 331, in run
    epoch_runner(data_loaders[i], **kwargs)
  File "/home/wenchi/projects/yolodet-pytorch-2/yolodet/apis/runner.py", line 214, in train
    for i, data_batch in enumerate(data_loader):
  File "/home/wenchi/miniconda3/envs/yolodet-2/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 521, in __next__
    data = self._next_data()
  File "/home/wenchi/miniconda3/envs/yolodet-2/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
    return self._process_data(data)
  File "/home/wenchi/miniconda3/envs/yolodet-2/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
    data.reraise()
  File "/home/wenchi/miniconda3/envs/yolodet-2/lib/python3.7/site-packages/torch/_utils.py", line 425, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/wenchi/miniconda3/envs/yolodet-2/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/wenchi/miniconda3/envs/yolodet-2/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/wenchi/miniconda3/envs/yolodet-2/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/wenchi/projects/yolodet-pytorch-2/yolodet/dataset/custom.py", line 112, in __getitem__
    data = self.prepare_train_img(idx)
  File "/home/wenchi/projects/yolodet-pytorch-2/yolodet/dataset/custom.py", line 106, in prepare_train_img
    return self.pipeline(results)
  File "/home/wenchi/projects/yolodet-pytorch-2/yolodet/dataset/pipelines/compose.py", line 47, in __call__
    data = t(data)
  File "/home/wenchi/projects/yolodet-pytorch-2/yolodet/dataset/pipelines/transforms.py", line 139, in __call__
    hsv[1] *= dsat
TypeError: 'tuple' object does not support item assignment

Hey guys, when I try to run the model on both COCO and my own custom dataset, I ran into the above error. I am sure that the annotation format is correct. Do you have some idea how to fix it?

One more thing that I am not clear is the label.names. Could you show me the format of the label.names? Could the above error caused by the label.names when doing data loading?

Thank you very much!

Wenchi

onnx

是否有onnx转换支持。

关于iou-aware分支在inference时的问题

你好,我想问下在ppyolo中添加的iou-aware分支,在inference时,原论文中的iou confidence是通过α=0.4次方的形式与class的confidence的0.6次方相乘,得到inference时的confidence。
但是在代码中,yolodet/models/heads/ppyolo.py中的get_eval_bboxes函数:
new_obj = torch.pow(obj, (1 - self.iou_aware_factor)) * torch.pow(ioua, self.iou_aware_factor)
实现论文的new_obj以后还进行了-log(1/new_obj-1)的操作。
我这边实现了iou-aware后假设原new_obj为0.9,但是经过-log(1/new_obj-1)后续操作得到的confidence数值是2.19,造成了识别的confidence的范围不在0到1以内。
想请教下为什么代码中这样实现,还是说在其他地方有将其重新约束到(0,1)的操作?

你好,我在训练出错

Traceback (most recent call last):
File "tools/train.py", line 144, in
main()
File "tools/train.py", line 69, in main
cfg = Config.fromfile(args.config)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/utils/config.py", line 174, in fromfile
cfg_dict, cfg_text = Config._file2dict(filename)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/utils/config.py", line 113, in _file2dict
mod = import_module('_tempconfig')
File "/home/tongyu/.conda/envs/yolodet/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 674, in exec_module
File "", line 781, in get_code
File "", line 741, in source_to_code
File "", line 219, in _call_with_frames_removed
File "/tmp/tmpwcunctkd/_tempconfig.py", line 37
bbox_loss=dict(type='IOU_Loss', iou_type='GIOU',loss_weight=0.05),
^
SyntaxError: invalid syntax

训练两个epoch之后依然报错,希望得到大家的帮助

train words:python tools/train.py --work_dir results cfg/yolov5_coco_100e.py --device 0 --validate

Traceback (most recent call last):
File "tools/train.py", line 144, in
main()
File "tools/train.py", line 140, in main
train_detector(model,datasets,cfg,validate=args.validate,timestamp=timestamp,meta=meta)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/apis/train.py", line 161, in train_detector
runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/apis/runner.py", line 331, in run
epoch_runner(data_loaders[i], **kwargs)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/apis/runner.py", line 230, in train
self.call_hook('after_train_epoch')
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/apis/runner.py", line 205, in call_hook
getattr(hook, fn_name)(self)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/models/hooks/eval_hook.py", line 52, in after_train_epoch
results = single_gpu_test(model, self.dataloader)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/apis/test.py", line 93, in single_gpu_test
output = non_max_suppression(inf_out, conf_thres=conf_thres, iou_thres=iou_thres, merge=merge)
File "/home/tongyu/develop-project/yolodet-pytorch-master/yolodet/models/heads/base.py", line 355, in non_max_suppression
i = torchvision.ops.boxes.nms(boxes, scores, iou_thres)
File "/home/tongyu/.conda/envs/yolodet/lib/python3.6/site-packages/torchvision/ops/boxes.py", line 40, in nms
return torch.ops.torchvision.nms(boxes, scores, iou_threshold)
RuntimeError: Trying to create tensor with negative dimension -1203535890: [-1203535890]

yolov5使用注意

首先感谢作者的分享!
使用yolov5的小伙伴注意,里面有一些bug和一些不完善的地方,直接使用即使训练300轮的mAP依然非常底!!!比如config配置,model,loss单分类的计算,数据增强等。建议自己用yolo5源码实现,不然bug都不知道在哪。

dataloader 报错

RuntimeError: Caught RuntimeError in DataLoader worker process 3.
Original Traceback (most recent call last):
File "/root/.local/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
data = fetcher.fetch(index)
File "/root/.local/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
return self.collate_fn(data)
File "/root/liyang/yolodet-pytorch/yolodet/dataset/loader/build_dataloader.py", line 92, in collate
clt[k] = torch.stack(v, 0)
RuntimeError: stack expects each tensor to be equal size, but got [3, 640, 640] at entry 0 and [3, 1280, 1280] at entry 6

是loader/build_dataloader.py 里面collate的问题?

File "/var/folders/l8/b9v1kgkd6nz9hl__21wh79hm0000gn/T/tmp0dmyw5s2/_tempconfig.py", line 37 bbox_loss=dict(type='IOU_Loss', iou_type='GIOU',loss_weight=0.05), ^

你好 @wuzhihao7788

我在mac上训练报错,

Traceback (most recent call last):
File "tools/train.py", line 144, in
main()
File "tools/train.py", line 69, in main
cfg = Config.fromfile(args.config)
File "/Users/youyin/Documents/人工智能研究项目/keypoint/yolodet-pytorch/yolodet/utils/config.py", line 173, in fromfile
cfg_dict, cfg_text = Config._file2dict(filename)
File "/Users/youyin/Documents/人工智能研究项目/keypoint/yolodet-pytorch/yolodet/utils/config.py", line 113, in _file2dict
mod = import_module('_tempconfig')
File "/Users/youyin/anaconda3/envs/yolodet/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 724, in exec_module
File "", line 860, in get_code
File "", line 791, in source_to_code
File "", line 219, in _call_with_frames_removed
File "/var/folders/l8/b9v1kgkd6nz9hl__21wh79hm0000gn/T/tmp0dmyw5s2/_tempconfig.py", line 37
bbox_loss=dict(type='IOU_Loss', iou_type='GIOU',loss_weight=0.05),
^
SyntaxError: invalid syntax

mixup增广怎么用

请问mixup增广在没加进去,我直接用,精度下降;把mixup的分数加到qfl的weight上好像也没提升

请问:测试的时候出现这种错误怎么办,还有所得到的result的构成是怎样的?

错误:show_result(img, result, model.CLASSES)
File "yolodet-pytorch/yolodet/apis/inference.py", line 168, in show_result
label = rslt['label']
IndexError: too many indices for tensor of dimension 3

代码:
from yolodet.apis.inference import inference_detector,init_detector,show_result
import os

config_file ='cfg/yolov4_gpu.py'
checkpoint_file ='work_dirs/yolov4/latest.pth'

build the model from a config file and a checkpoint file

model = init_detector(config_file, checkpoint_file, device='cuda:0')

test a single image and show the results

img ='test.jpg' # or img = mmcv.imread(img), which will only load it once
result,t = inference_detector(model, img)
print('%s Done , object num : %s .time:(%.3fs)' % (img,len(result), t))

visualize the results in a new window

show_result(img, result, model.CLASSES)

yolov5 model struct bug.

感谢开源此项目!
yolov5项目模型结构有问题

  • backbone中CSP_2_1是属于Neck部分
  • Neck多输出了一个data,但是在Head中又去除了那个data.

没有仔细看你的代码构建,就算最终结果没问题,但是代码可读性变差了

你好,我使用单卡可以训练,当使用多卡时,会出错,请问你尝试过多卡训练吗?

Traceback (most recent call last):
File "tools/train.py", line 144, in
main()
File "tools/train.py", line 140, in main
train_detector(model,datasets,cfg,validate=args.validate,timestamp=timestamp,meta=meta)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/apis/train.py", line 161, in train_detector
runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/apis/runner.py", line 331, in run
epoch_runner(data_loaders[i], **kwargs)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/apis/runner.py", line 220, in train
self.model, data_batch, train_mode=True, **kwargs)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/apis/train.py", line 116, in batch_processor
losses = model(**data)
File "/data4/xieyangyang/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "/data4/xieyangyang/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 155, in forward
outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/data4/xieyangyang/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 165, in parallel_apply
return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
File "/data4/xieyangyang/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/parallel_apply.py", line 85, in parallel_apply
output.reraise()
File "/data4/xieyangyang/anaconda3/lib/python3.7/site-packages/torch/_utils.py", line 395, in reraise
raise self.exc_type(msg)
RuntimeError: Caught RuntimeError in replica 0 on device 0.
Original Traceback (most recent call last):
File "/data4/xieyangyang/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/parallel_apply.py", line 60, in _worker
output = module(*input, **kwargs)
File "/data4/xieyangyang/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/models/detectors/base.py", line 55, in forward
return self.forward_train(img, img_metas, **kwargs)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/models/detectors/YOLOv5Detector.py", line 100, in forward_train
head_loss = self.head.loss(*head_loss_inputs)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/models/heads/yolo.py", line 99, in loss
bbox_loss, confidence_loss, class_loss = multi_apply(self.loss_single, pred, indices,tbox,tcls,ancher,self.conf_balances,ignore_mask)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/utils/util.py", line 32, in multi_apply
return tuple(map(list, zip(*map_results)))
File "/data1/xieyangyang/yolodet-pytorch/yolodet/models/heads/yolo.py", line 91, in loss_single
return self.yolov5_loss_single(pred, indices,tbox,tcls,anchors, conf_balances,ignore_mask)
File "/data1/xieyangyang/yolodet-pytorch/yolodet/models/heads/yolo.py", line 210, in yolov5_loss_single
pwh = (ps[:, 2:4].sigmoid() * 2) ** 2 * torch.from_numpy(anchors).to(device) # 0-4倍缩放 model.hyp['anchor_t']=4
RuntimeError: CUDA error: device-side assert triggered

使用yolov4_coco_100e的cfg训练网络,计算map过程特别慢

您好,非常感谢您能够提供这么好的yolo框架。但是我在使用yolov4_coco_100e的cfg文集训练时,计算map的过程特别慢,计算一次map要花费6分钟的时间。我使用的batch_size=8,subdivisions=4,使用的数据集共2500张,测试集有600张,gpu是1080的。我在u版的yolo上使用yolov4训练我的数据相同的设置计算map只需要30秒的时间,请问这里面是哪里出了问题?

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.