mobilenetv3-centernet tensorflow 实现

4 篇文章 0 订阅
2 篇文章 0 订阅

Centernet 移动端的优化

简介

centernet 是一个很简洁的目标检测框架,原理很简单,关键点估计加宽高回归。
文章不介绍算法细节, 主要是一个centernet在端侧的优化。

backbone 采用了mobilenetv3,但是只改backbone 提速不够,head 还是比较重的,所以采用可分离卷积来实现,并且采用了类似inception的结构,并把深层和浅层的特征进行了融合,取得了还算可以的效果,当然如果不关注小目标,还是可以继续优化的。

centernet 思路是十分简单的, heatmap 找出目标的中心,wh 找出该中心的宽高, 核心就是如此。至于loss 函数,这些都是为了

source

github

pretrained model , and preformance

mscoco

modelinput_sizemapmap@0.5map@0.75
mbv3-large-0.75-modified_head512x5120.2250.4010.224

fddb

modelinput_sizefddb
mbv3-small-minimalistic_modified512x5120.95

widerface

modelinput_sizewider easywider mediumwider hard
mbv3-small-minimalistic_modified512x5120.8420.7900.455

requirment

  • tensorflow 1.14

  • tensorpack 0.9.9 (for data provider)

  • opencv

  • python 3.6

  • MNNConverter

  • tfcoreml

使用方法

MSCOCO

train
  1. 下载数据download mscoco data, 然后 python prepare_coco_data.py --mscocodir ./mscoco. (数据格式还是img_path| x1,y1,x2,y2,label… ( label 从0 开始),如果训练自己数据就这样来就行)

  2. 下载预训练模型
    mbv3-large0.75
    解压

  3. 改 config=mb3_config in train_config.py, 然后:

    python train.py

    如果想可视化一下数据 可以设置 confifs/mscoco/mbv3_config.py 为 True

  4. 训练完, freezeas .pb by

    python tools/auto_freeze.py --pretrained_mobile ./model/yourmodel.ckpt

    it will produce a detector.pb

evaluation
python model_eval/custome_eval.py [--model [TRAINED_MODEL]] [--annFile [cocostyle annFile]]
                          [--imgDir [the images dir]] [--is_show [show the result]]

python model_eval/custome_eval.py --model model/detector.pb
                                --annFile ../mscoco/annotations/instances_val2017.json
                                --imgDir ../mscoco/val2017
                                --is_show 1

ps, no test time augmentation is used.

FACE

train
  1. 下载 widerface data http://shuoyang1213.me/WIDERFACE/,
    and release the WIDER_train, WIDER_val and wider_face_split into ./WIDER,
    then run python prepare_wider_data.py

  2. download pretrained model from mbv3-small-minimalistic
    release it in current dir

  3. then, modify in config=face_config in train_config.py, then run:

    python train.py

    and if u want to check the data when training, u could set vis in confifs/mscoco/mbv3_config.py as True

  4. After training, freeze the model as .pb by

    python tools/auto_freeze.py --pretrained_mobile ./model/yourmodel.ckpt

    it will produce a detector.pb

evaluation

** fddb **

    python model_eval/fddb.py [--model [TRAINED_MODEL]] [--data_dir [DATA_DIR]]
                          [--split_dir [SPLIT_DIR]] [--result [RESULT_DIR]]
    --model              Path of the saved model,default ./model/detector.pb
    --data_dir           Path of fddb all images
    --split_dir          Path of fddb folds
    --result             Path to save fddb results

example python model_eval/fddb.py --model model/detector.pb --data_dir 'fddb/img/' --split_dir fddb/FDDB-folds/ --result 'result/'

** widerface **

    python model_eval/wider.py [--model [TRAINED_MODEL]] [--data_dir [DATA_DIR]]
                           [--result [RESULT_DIR]]
    --model              Path of the saved model,default ./model/detector.pb
    --data_dir           Path of WIDER
    --result             Path to save WIDERface results

example python model_eval/wider.py --model model/detector.pb --data_dir 'WIDER/WIDER_val/' --result 'result/'

finetune

  1. 下载模型
    然后改config config.MODEL.pretrained_model=‘yourmodel.ckpt’,
    config.MODEL.continue_train=True
  2. python train.py

visualization

把图固定,其实很多人用tensorflow,都不太熟悉,导致转换模型的时候总是各种op报错,需要把training_flag 写死成false, 在freeze pb的时候才会进行图优化,从而把一些op fuse,最常见的就是batchnorm这个op,很多人工作多少年了,batchnorm都说不清。

python tools/auto_freeze.py --pretrained_model your.ckpt, 会产生一个detector.pb

python visualization/vis.py

model convert for mobile device

后处理已经经过适配了,在MNN和coreml上都可以端到端的转换

4.1 MNN

+ 4.1.1 convert model

    直接用mnn的api,
    `./MNNConvert -f TF --modelFile detector.pb --MNNModel centernet.mnn --bizCode biz  --fp16 1`

+ 4.1.2 visualization with mnn python wrapper

    `python visualization/vis_with_mnn.py --mnn_model centernet.mnn --imgDir 'your image dir'`

4.2 coreml

+ 4.2.1 convert

    `python tools/converter_to_coreml.py`

+ 4.2.2 visualization with coreml python wrapper

    `python visualization/vis_with_coreml.py --coreml_model centernet.mlmodel --imgDir 'your image dir'`

ps, if you want to do quantization, please reffer to the official doc, it is easy.

TODO:

  • Android project.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值