ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

RetinaFace MXNet模型转ONNX转TensorRT

2020-12-05 09:59:40  阅读:658  来源: 互联网

标签:RetinaFace engine MXNet ONNX 模型 file onnx


文章目录

RetinaFace MXNet模型转ONNX转TensorRT

1. github开源代码

RetinaFace TensorRT推理的开源代码位置在https://github.com/linghu8812/tensorrt_inference/tree/master/RetinaFace

2. MXNet模型转ONNX模型

首先通过命令git clone https://github.com/deepinsight/insightface.gitclone insightface的代码,然后将export_onnx.py文件拷贝到./detection/RetinaFace或者./detection/RetinaFaceAntiCov文件夹中,通过以下命令生成ONNX文件。对于RetinaFace-R50RetinaFace-MobileNet0.25RetinaFaceAntiCov这几个模型都可以支持。通过以下命令可以导出模型:

  • 导出resnet50模型
python3 export_onnx.py
  • 导出mobilenet 0.25模型
python3 export_onnx.py  --prefix ./model/mnet.25
  • 导出RetinaFaceAntiCov模型
python3 export_onnx.py  --prefix ./model/mnet_cov2 --network net3l

YOLOv4模型一样,对输出结果也做了concat,如下图所示。
在这里插入图片描述

3. ONNX模型转TensorRT模型

3.1 概述

TensorRT模型即TensorRT的推理引擎,代码中通过C++实现。相关配置写在config.yaml文件中,如果存在engine_file的路径,则读取engine_file,否则从onnx_file生成engine_file

void RetinaFace::LoadEngine() {
    // create and load engine
    std::fstream existEngine;
    existEngine.open(engine_file, std::ios::in);
    if (existEngine) {
        readTrtFile(engine_file, engine);
        assert(engine != nullptr);
    } else {
        onnxToTRTModel(onnx_file, engine_file, engine, BATCH_SIZE);
        assert(engine != nullptr);
    }
}

config.yaml文件可以设置batch size,图像的size及模型的anchor等。

RetinaFace:
    onnx_file:     "../R50.onnx"
    engine_file:   "../R50.trt"
    BATCH_SIZE:    1
    INPUT_CHANNEL: 3
    IMAGE_WIDTH:   640
    IMAGE_HEIGHT:  640
    obj_threshold: 0.5
    nms_threshold: 0.45
    detect_mask:   False
    mask_thresh:   0.5
    landmark_std:  1
    feature_steps: [32, 16, 8]
    anchor_sizes:  [[512, 256], [128, 64], [32, 16]]

3.2 编译

通过以下命令对项目进行编译,生成RetinaFace_trt

mkdir build && cd build
cmake ..
make -j

3.3 运行

通过以下命令运行项目,得到推理结果

  • RetinaFace模型推理
./RetinaFace_trt../config.yaml ../samples
  • RetinaFaceAntiCov模型推理
./RetinaFace_trt ../config_anti.yaml ../samples

4. 推理结果

  • RetinaFace推理结果:
    在这里插入图片描述
  • RetinaFaceAntiCov推理结果:
    在这里插入图片描述

标签:RetinaFace,engine,MXNet,ONNX,模型,file,onnx
来源: https://blog.csdn.net/linghu8812/article/details/110677016

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有