这是一个yolox-keras的源码,可以用于训练自己的模型。

Overview

YOLOX:You Only Look Once目标检测模型在Keras当中的实现


目录

  1. 性能情况 Performance
  2. 实现的内容 Achievement
  3. 所需环境 Environment
  4. 小技巧的设置 TricksSet
  5. 文件下载 Download
  6. 训练步骤 How2train
  7. 预测步骤 How2predict
  8. 评估步骤 How2eval
  9. 参考资料 Reference

性能情况

训练数据集 权值文件名称 测试数据集 输入图片大小 mAP 0.5:0.95 mAP 0.5
COCO-Train2017 yolox_s.h5 COCO-Val2017 640x640 39.2 58.7
COCO-Train2017 yolox_m.h5 COCO-Val2017 640x640 46.1 65.2
COCO-Train2017 yolox_l.h5 COCO-Val2017 640x640 49.3 68.1
COCO-Train2017 yolox_x.h5 COCO-Val2017 640x640 50.5 69.2

实现的内容

  • 主干特征提取网络:使用了Focus网络结构。
  • 分类回归层:Decoupled Head,在YoloX中,Yolo Head被分为了分类回归两部分,最后预测的时候才整合在一起。
  • 训练用到的小技巧:Mosaic数据增强、CIOU(原版是IOU和GIOU,CIOU效果类似,都是IOU系列的,甚至更新一些)、学习率余弦退火衰减。
  • Anchor Free:不使用先验框
  • SimOTA:为不同大小的目标动态匹配正样本。

所需环境

tensorflow-gpu==1.13.1
keras==2.1.5

小技巧的设置

在train.py文件下:
1、mosaic参数可用于控制是否实现Mosaic数据增强。
2、Cosine_scheduler可用于控制是否使用学习率余弦退火衰减。
3、label_smoothing可用于控制是否Label Smoothing平滑。

文件下载

训练所需的权值可在百度网盘中下载。
链接: https://pan.baidu.com/s/1o14Vi-CzZEaz9hic_OPZCQ 提取码: 4kc2

VOC数据集下载地址如下:
VOC2007+2012训练集
链接: https://pan.baidu.com/s/16pemiBGd-P9q2j7dZKGDFA 提取码: eiw9

VOC2007测试集
链接: https://pan.baidu.com/s/1BnMiFwlNwIWG9gsd4jHLig 提取码: dsda

训练步骤

a、数据集的准备

1、本文使用VOC格式进行训练,训练前需要自己制作好数据集,如果没有自己的数据集,可以通过Github连接下载VOC12+07的数据集尝试下。
2、训练前将标签文件放在VOCdevkit文件夹下的VOC2007文件夹下的Annotation中。
3、训练前将图片文件放在VOCdevkit文件夹下的VOC2007文件夹下的JPEGImages中。

b、数据集的预处理

1、训练数据集时,在model_data文件夹下建立一个cls_classes.txt,里面写所需要区分的类别。
2、设置根目录下的voc_annotation.py里的一些参数。第一次训练可以仅修改classes_path,classes_path用于指向检测类别所对应的txt,即:

classes_path = 'model_data/cls_classes.txt'

model_data/cls_classes.txt文件内容为:

cat
dog
...

3、设置完成后运行voc_annotation.py,生成训练所需的2007_train.txt以及2007_val.txt。

c、开始网络训练

1、通过voc_annotation.py,我们已经生成了2007_train.txt以及2007_val.txt,此时我们可以开始训练了。
2、设置根目录下的train.py里的一些参数。第一次训练可以仅修改classes_path,classes_path用于指向检测类别所对应的txt,设置方式与b、数据集的预处理类似。训练自己的数据集必须要修改!
3、设置完成后运行train.py开始训练了,在训练多个epoch后,权值会生成在logs文件夹中。
4、训练的参数较多,大家可以在下载库后仔细看注释,其中最重要的部分依然是train.py里的classes_path。

d、训练结果预测

1、训练结果预测需要用到两个文件,分别是yolo.py和predict.py。
2、设置根目录下的yolo.py里的一些参数。第一次预测可以仅修改model_path以及classes_path。训练自己的数据集必须要修改。model_path指向训练好的权值文件,在logs文件夹里。classes_path指向检测类别所对应的txt。
3、设置完成后运行predict.py开始预测了,具体细节查看预测步骤。
4、预测的参数较多,大家可以在下载库后仔细看注释,其中最重要的部分依然是yolo.py里的model_path以及classes_path。

预测步骤

a、使用预训练权重

1、下载完库后解压,在百度网盘下载各个权值,放入model_data,默认使用yolox_s.h5,其它可调整,运行predict.py,输入

img/street.jpg

2、在predict.py里面进行设置可以进行video视频检测、fps测试、批量文件测试与保存。

b、使用自己训练的权重

1、按照训练步骤训练。
2、在yolo.py文件里面,在如下部分修改model_path和classes_path使其对应训练好的文件;model_path对应logs文件夹下面的权值文件,classes_path是model_path对应分的类

_defaults = {
    #--------------------------------------------------------------------------#
    #   使用自己训练好的模型进行预测一定要修改model_path和classes_path!
    #   model_path指向logs文件夹下的权值文件,classes_path指向model_data下的txt
    #   如果出现shape不匹配,同时要注意训练时的model_path和classes_path参数的修改
    #--------------------------------------------------------------------------#
    "model_path"        : 'model_data/yolox_s.h5',
    "classes_path"      : 'model_data/coco_classes.txt',
    #---------------------------------------------------------------------#
    #   输入图片的大小,必须为32的倍数。
    #---------------------------------------------------------------------#
    "input_shape"       : [640, 640],
    #---------------------------------------------------------------------#
    #   所使用的YoloX的版本。s、m、l、x
    #---------------------------------------------------------------------#
    "phi"               : 's',
    #---------------------------------------------------------------------#
    #   只有得分大于置信度的预测框会被保留下来
    #---------------------------------------------------------------------#
    "confidence"        : 0.5,
    #---------------------------------------------------------------------#
    #   非极大抑制所用到的nms_iou大小
    #---------------------------------------------------------------------#
    "nms_iou"           : 0.3,
    "max_boxes"         : 100,
    #---------------------------------------------------------------------#
    #   该变量用于控制是否使用letterbox_image对输入图像进行不失真的resize,
    #   在多次测试后,发现关闭letterbox_image直接resize的效果更好
    #---------------------------------------------------------------------#
    "letterbox_image"   : True,
}

3、运行predict.py,输入

img/street.jpg

4、在predict.py里面进行设置可以进行video视频检测、fps测试、批量文件测试与保存。

评估步骤

1、本文使用VOC格式进行评估。
2、划分测试集,如果在训练前已经运行过voc_annotation.py文件,代码会自动将数据集划分成训练集、验证集和测试集。
3、如果想要修改测试集的比例,可以修改voc_annotation.py文件下的trainval_percent。trainval_percent用于指定(训练集+验证集)与测试集的比例,默认情况下 (训练集+验证集):测试集 = 9:1。train_percent用于指定(训练集+验证集)中训练集与验证集的比例,默认情况下 训练集:验证集 = 9:1。
4、设置根目录下的yolo.py里的一些参数。第一次评估可以仅修改model_path以及classes_path。训练自己的数据集必须要修改。model_path指向训练好的权值文件,在logs文件夹里。classes_path指向检测类别所对应的txt。
5、设置根目录下的get_map.py里的一些参数。第一次评估可以仅修改classes_path,classes_path用于指向检测类别所对应的txt,评估自己的数据集必须要修改。与yolo.py中分开设置的原因是可以让使用者自己选择评估什么类别,而非所有类别。
6、运行get_map.py即可获得评估结果,评估结果会保存在map_out文件夹中。

Reference

https://github.com/Megvii-BaseDetection/YOLOX

You might also like...
Comments
  • using yolox_keras as backbone/pretrained model wanted

    using yolox_keras as backbone/pretrained model wanted

    many will try using different backbones like yolo/VGG/ENet for their models and it will be usefull if you have a pretrained model that doesn't include top layers for them. I also tried to find the saved model as it has to be in this directory :'model_data/yolox_s.h5' but it isn't if you still have the model I'll appreciate to upload it again. because I tried to train the model but found some issues with utils and loading data. Thanks

    opened by asparsa 1
  • tf与keras兼容问题报错

    tf与keras兼容问题报错

    !python predict.py 报错如下: model_data/yolox_s.h5 model, and classes loaded. Traceback (most recent call last): File "predict.py", line 14, in yolo = YOLO() File "/content/yolox-keras/yolo.py", line 82, in init self.boxes, self.scores, self.classes = self.generate() File "/content/yolox-keras/yolo.py", line 106, in generate letterbox_image = self.letterbox_image File "/content/yolox-keras/utils/utils_bbox.py", line 73, in DecodeBox grid_x, grid_y = tf.meshgrid(K.arange(hw[i][1]), K.arange(hw[i][0])) File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler raise e.with_traceback(filtered_tb) from None File "/usr/local/lib/python3.7/dist-packages/keras/layers/core/tf_op_layer.py", line 107, in handle return TFOpLambda(op)(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/usr/local/lib/python3.7/dist-packages/keras/backend.py", line 3510, in arange if stop is None and start < 0: tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: Exception encountered when calling layer "tf.keras.backend.arange" (type TFOpLambda).

    using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.

    Call arguments received: • start=tf.Tensor(shape=(), dtype=int32) • stop=None • step=1 • dtype=int32

    修改:utils.utils_bbox.DecodeBox如下: @tf.function def DecodeBox()

    接着报错: model_data/yolox_s.h5 model, and classes loaded. Traceback (most recent call last): File "predict.py", line 14, in yolo = YOLO() File "/content/yolox-keras/yolo.py", line 82, in init self.boxes, self.scores, self.classes = self.generate() File "/content/yolox-keras/yolo.py", line 106, in generate letterbox_image = self.letterbox_image File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler raise e.with_traceback(filtered_tb) from None File "/usr/local/lib/python3.7/dist-packages/keras/engine/keras_tensor.py", line 256, in array f'You are passing {self}, an intermediate Keras symbolic input/output, ' TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 85), dtype=tf.float32, name=None), name='concatenate_13/concat:0', description="created by layer 'concatenate_13'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as tf.cond, tf.function, gradient tapes, or tf.map_fn. Keras Functional model construction only supports TF API calls that do support dispatching, such as tf.math.add or tf.reshape. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer call and calling that layer on this symbolic input/output.

    opened by cyning911 17
Releases(v2.1)
Owner
Bubbliiiing
Bubbliiiing
AFL binary instrumentation

E9AFL --- Binary AFL E9AFL inserts American Fuzzy Lop (AFL) instrumentation into x86_64 Linux binaries. This allows binaries to be fuzzed without the

242 Dec 12, 2022
Use of Attention Gates in a Convolutional Neural Network / Medical Image Classification and Segmentation

Attention Gated Networks (Image Classification & Segmentation) Pytorch implementation of attention gates used in U-Net and VGG-16 models. The framewor

Ozan Oktay 1.6k Dec 30, 2022
COVID-VIT: Classification of Covid-19 from CT chest images based on vision transformer models

COVID-ViT COVID-VIT: Classification of Covid-19 from CT chest images based on vision transformer models This code is to response to te MIA-COV19 compe

17 Dec 30, 2022
Pytorch implementation for "Adversarial Robustness under Long-Tailed Distribution" (CVPR 2021 Oral)

Adversarial Long-Tail This repository contains the PyTorch implementation of the paper: Adversarial Robustness under Long-Tailed Distribution, CVPR 20

Tong WU 89 Dec 15, 2022
Convolutional Neural Network for 3D meshes in PyTorch

MeshCNN in PyTorch SIGGRAPH 2019 [Paper] [Project Page] MeshCNN is a general-purpose deep neural network for 3D triangular meshes, which can be used f

Rana Hanocka 1.4k Jan 04, 2023
Research on controller area network Intrusion Detection Systems

Group members information Member 1: Lixue Liang Member 2: Yuet Lee Chan Member 3: Xinruo Zhang Member 4: Yifei Han User Manual Generate Attack Packets

Roche 4 Aug 30, 2022
Implicit MLE: Backpropagating Through Discrete Exponential Family Distributions

torch-imle Concise and self-contained PyTorch library implementing the I-MLE gradient estimator proposed in our NeurIPS 2021 paper Implicit MLE: Backp

UCL Natural Language Processing 249 Jan 03, 2023
SberSwap Video Swap base on deep learning

SberSwap Video Swap base on deep learning

Sber AI 431 Jan 03, 2023
Python code to fuse multiple RGB-D images into a TSDF voxel volume.

Volumetric TSDF Fusion of RGB-D Images in Python This is a lightweight python script that fuses multiple registered color and depth images into a proj

Andy Zeng 845 Jan 03, 2023
(CVPR 2022) Energy-based Latent Aligner for Incremental Learning

Energy-based Latent Aligner for Incremental Learning Accepted to CVPR 2022 We illustrate an Incremental Learning model trained on a continuum of tasks

Joseph K J 37 Jan 03, 2023
Deep-learning X-Ray Micro-CT image enhancement, pore-network modelling and continuum modelling

EDSR modelling A Github repository for deep-learning image enhancement, pore-network and continuum modelling from X-Ray Micro-CT images. The repositor

Samuel Jackson 7 Nov 03, 2022
Extreme Rotation Estimation using Dense Correlation Volumes

Extreme Rotation Estimation using Dense Correlation Volumes This repository contains a PyTorch implementation of the paper: Extreme Rotation Estimatio

Ruojin Cai 29 Nov 18, 2022
Rainbow: Combining Improvements in Deep Reinforcement Learning

Rainbow Rainbow: Combining Improvements in Deep Reinforcement Learning [1]. Results and pretrained models can be found in the releases. DQN [2] Double

Kai Arulkumaran 1.4k Dec 29, 2022
Pytorch and Keras Implementations of Hyperspectral Image Classification -- Traditional to Deep Models: A Survey for Future Prospects.

The repository contains the implementations for Hyperspectral Image Classification -- Traditional to Deep Models: A Survey for Future Prospects. Model

Ankur Deria 115 Jan 06, 2023
Towards Calibrated Model for Long-Tailed Visual Recognition from Prior Perspective

Towards Calibrated Model for Long-Tailed Visual Recognition from Prior Perspective Zhengzhuo Xu, Zenghao Chai, Chun Yuan This is the PyTorch implement

Sincere 16 Dec 15, 2022
The implementation of ICASSP 2020 paper "Pixel-level self-paced learning for super-resolution"

Pixel-level Self-Paced Learning for Super-Resolution This is an official implementaion of the paper Pixel-level Self-Paced Learning for Super-Resoluti

Elon Lin 41 Dec 15, 2022
Exploiting Robust Unsupervised Video Person Re-identification

Exploiting Robust Unsupervised Video Person Re-identification Implementation of the proposed uPMnet. For the preprint, please refer to [Arxiv]. Gettin

1 Apr 09, 2022
Pytorch implementation of Distributed Proximal Policy Optimization: https://arxiv.org/abs/1707.02286

Pytorch-DPPO Pytorch implementation of Distributed Proximal Policy Optimization: https://arxiv.org/abs/1707.02286 Using PPO with clip loss (from https

Alexis David Jacq 163 Dec 26, 2022
This repository contains a pytorch implementation of "HeadNeRF: A Real-time NeRF-based Parametric Head Model (CVPR 2022)".

HeadNeRF: A Real-time NeRF-based Parametric Head Model This repository contains a pytorch implementation of "HeadNeRF: A Real-time NeRF-based Parametr

294 Jan 01, 2023