Giter VIP home page Giter VIP logo

retinaface-keras's Introduction

Retinaface:人脸检测模型在Keras当中的实现


目录

  1. 仓库更新 Top News
  2. 性能情况 Performance
  3. 所需环境 Environment
  4. 文件下载 Download
  5. 预测步骤 How2predict
  6. 训练步骤 How2train
  7. 评估步骤 Eval
  8. 参考资料 Reference

Top News

2022-03:进行了大幅度的更新,支持step、cos学习率下降法、支持adam、sgd优化器选择、支持学习率根据batch_size自适应调整。
BiliBili视频中的原仓库地址为:https://github.com/bubbliiiing/retinaface-keras/tree/bilibili

2020-09:仓库创建,支持模型训练,大量的注释,多个主干的选择,多个可调整参数。

性能情况

训练数据集 权值文件名称 测试数据集 输入图片大小 Easy Medium Hard
Widerface-Train retinaface_mobilenet025.h5 Widerface-Val 1280x1280 88.94% 86.76% 73.83%
Widerface-Train retinaface_resnet50.h5 Widerface-Val 1280x1280 94.69% 93.08% 84.31%

所需环境

tensorflow-gpu==1.13.1
keras==2.1.5

文件下载

训练所需的retinaface_resnet50.h5、resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5等文件可以在百度云下载。
链接: https://pan.baidu.com/s/1iiIqjlrtpvMjh_s2RsjSag 提取码: dru9

数据集可以在如下连接里下载。
链接: https://pan.baidu.com/s/1bsgay9iMihPlAKE49aWNTA 提取码: bhee

预测步骤

a、使用预训练权重

  1. 下载完库后解压,运行predict.py,输入
img/timg.jpg
  1. 在predict.py里面进行设置可以进行fps测试和video视频检测。

b、使用自己训练的权重

  1. 按照训练步骤训练。
  2. 在retinaface.py文件里面,在如下部分修改model_path和backbone使其对应训练好的文件。
_defaults = {
    "model_path"        : 'model_data/retinaface_mobilenet025.h5',
    "backbone"          : 'mobilenet',
    "confidence"        : 0.5,
    "nms_iou"           : 0.45,
    #----------------------------------------------------------------------#
    #   是否需要进行图像大小限制。
    #   开启后,会将输入图像的大小限制为input_shape。否则使用原图进行预测。
    #   keras代码中主干为mobilenet时存在小bug,当输入图像的宽高不为32的倍数
    #   会导致检测结果偏差,主干为resnet50不存在此问题。
    #----------------------------------------------------------------------#
    "input_shape"       : [1280, 1280, 3],
    "letterbox_image"   : True
}
  1. 运行predict.py,输入
img/timg.jpg
  1. 在predict.py里面进行设置可以进行fps测试和video视频检测。

训练步骤

  1. 本文使用widerface数据集进行训练。
  2. 可通过上述百度网盘下载widerface数据集。
  3. 覆盖根目录下的data文件夹。
  4. 根据自己需要选择从头开始训练还是在已经训练好的权重下训练,需要修改train.py文件下的代码,在训练时需要注意backbone和权重文件的对应。 使用mobilenet为主干特征提取网络的示例如下:
    从头开始训练:
#-------------------------------#
#   创立模型
#-------------------------------#
model = RetinaFace(cfg, backbone=backbone)
model_path = "model_data/mobilenet_2_5_224_tf_no_top.h5"
model.load_weights(model_path,by_name=True,skip_mismatch=True)

在已经训练好的权重下训练:

#-------------------------------#
#   创立模型
#-------------------------------#
model = RetinaFace(cfg, backbone=backbone)
model_path = "model_data/retinaface_mobilenet025.h5"
model.load_weights(model_path,by_name=True,skip_mismatch=True)
  1. 可以在logs文件夹里面获得训练好的权值文件。

评估步骤

  1. 在retinaface.py文件里面,在如下部分修改model_path和backbone使其对应训练好的文件。
_defaults = {
    "model_path"        : 'model_data/retinaface_mobilenet025.h5',
    "backbone"          : 'mobilenet',
    "confidence"        : 0.5,
    "nms_iou"           : 0.45,
    #----------------------------------------------------------------------#
    #   是否需要进行图像大小限制。
    #   开启后,会将输入图像的大小限制为input_shape。否则使用原图进行预测。
    #   keras代码中主干为mobilenet时存在小bug,当输入图像的宽高不为32的倍数
    #   会导致检测结果偏差,主干为resnet50不存在此问题。
    #----------------------------------------------------------------------#
    "input_shape"       : [1280, 1280, 3],
    "letterbox_image"   : True
}
  1. 下载好百度网盘上上传的数据集,其中包括了验证集,解压在根目录下。
  2. 运行evaluation.py即可开始评估。

Reference

https://github.com/biubug6/Pytorch_Retinaface

retinaface-keras's People

Contributors

bubbliiiing 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

Watchers

 avatar  avatar

retinaface-keras's Issues

主干网络模型问题

您好,我想基于您复现的retinaface代码在网络上做一些修改,包括损失上,现在很疑惑您用的这个从头训练的主干网络模型是怎么得到的呢,如果我自定义了一些网络层和损失,您的这个主干网络模型应该不可以直接用的吧。

从头训练没有与训练的效果好

您好,我在wideface数据集中做了一些数据清洗,并加入自己的小部分数据训练,为什么从头训练比在预模型上训练效果要差一些,如果我从头训练的话效果不好可以调整哪些从训练参数呢,感觉keras不想torch那样有很多训练参数可以调整

cannot import name 'backend'

Hi,up 主,我在 linux 下运行你的工程提示:

from utils import backend
ImportError: cannot import name 'backend'

请问需要怎么修改吗?

训练时出现的问题

@bubbliiiing 下面的情况不知有无碰到过?
环境:tf1.15 ubuntu16.04
在retinanet_training.py文件的类Generator函数__getitem__下: img = Image.open(self.imgs_path[i]) 出现: IndexError: list index out range.
Error的出现不固定,有时某个epoch不出问题, 有时候在某个index出问题。

修改 UpsampleLike

我在部署模型的过程中,由于平台不支持自定义的层,所以把您自定义的 **UpsampleLike直接修改为UpSampling2D,最中训练的结构也满足要求,但是在运行predict.py的过程中,随机输入一张图片,在Add节点就会出现shape不匹配的问题,在剪枝过程中也会因为shape不同,出错,这里得请教您下为什么不使用UpSampling2D,使用这个如何适用于不同的输入,请指教,感谢!

P3 = Conv2D_BN_Leaky(cfg['out_channel'], kernel_size=1, strides=1, padding='same', name='C3_reduced', leaky=leaky)(C3)

P4 = Conv2D_BN_Leaky(cfg['out_channel'], kernel_size=1, strides=1, padding='same', name='C4_reduced', leaky=leaky)(C4)

P5 = Conv2D_BN_Leaky(cfg['out_channel'], kernel_size=1, strides=1, padding='same', name='C5_reduced', leaky=leaky)(C5)

P5_upsampled = UpSampling2D(2)(P5)//修改

P4 = Add(name='P4_merged')([P5_upsampled, P4])

P4 = Conv2D_BN_Leaky(cfg['out_channel'], kernel_size=3, strides=1, padding='same', name='Conv_P4_merged', leaky=leaky)(P4)

P4_upsampled = UpSampling2D(2)(P4)//修改

P3 = Add(name='P3_merged')([P4_upsampled, P3])

P3 = Conv2D_BN_Leaky(cfg['out_channel'], kernel_size=3, strides=1, padding='same', name='Conv_P3_merged', leaky=leaky)(P3)

运行pretrain模型时遇到的问题

您好我在运行pretrain模型运行predict函数时,出现了shape不匹配的问题,我使用resnet同样进行了测试不会出现
请问我需要先根据你的pretrain模型进行重新训练吗?谢谢
ValueError: Layer #99 (named "batch_normalization_5"), weight <tf.Variable 'batch_normalization_5/gamma:0' shape=(32,) dtype=float32, numpy= array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], dtype=float32)> has shape (32,), but the saved weight has shape (64,).

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.