灵活转换YOLOV3模型

举报
梦幻水蓝-浅若夏沫 发表于 2020/11/28 21:10:20 2020/11/28
【摘要】 根据atlas300样例使用tensorflow模型转换,首先将cpkt模型文件转换为字典形式格式,即为,key-value,然后,根据自己的需要修改保存为pb文件的节点,最后使用omg进行转换。 注意不支持5维度,所以特别需要关注后处理。

Tensorflow模型转换为pb文件

使用https://github.com/YunYang1994/tensorflow-yolov3.git工程

主要关注convert_weight.pyh和freeze_graph.py文件

配置~/.bashrc

export  LD_LIBRARY_PATH="/home/huawei/ddk/ddk/uihost/lib"
export DDK_HOME="/home/huawei/ddk/ddk"

  1. 观察core/yolov3.py中的模型代码,注意scope部分,如果scope下的子函数中同一个算子进行了多次操作,则编号从0开始,否则没有编号,这里,后续在转换为pb时要用到;

1.png

第一种情况,由于Atlas300系列不支持5维度的转换,我们直接将后续的后处理进行注释掉,此时为,decode子函数为:2.png

此时发现freeze_graph.py文件为:3.png

第二种情况,分别对应如下:

4.png

5.png

注意发现,我们保存到pb中的均为每个预测操作的第三个拼接操作,concat_2;

2. 转换之后,进入到/home/huawei/ddk/ddk/uihost/bin目录下,执行omg指令转换模型:

./omg --model /home/huawei/yolov3/tensorflow-yolov3/yolov3_coco.pb --framework 3 --output /home/huawei/yolov3/tensorflow_yolov3 --insert_op_conf /home/huawei/samples/Samples/InferObjectDetection/data/models/aipp_yolov3_picture.cfg --input_shape "input/input_data:1,416,416,3"

根据./omg -h 查看所有参数含义

3.进入 /home/huawei/samples/Samples/InferObjectDetection/目录,执行bash build.sh 进行编译

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/huawei/samples/Samples/InferObjectDetection/out
Scanning dependencies of target ObjectDetection
Scanning dependencies of target Device
14%] Building CXX object device/CMakeFiles/Device.dir/home/huawei/samples/Samples/InferObjectDetection/ObjectDetectionEngine/yolov3post.cpp.o
28%] Building CXX object host/CMakeFiles/ObjectDetection.dir/home/huawei/samples/Samples/InferObjectDetection/DstEngine/DstEngine.cpp.o
42%] Building CXX object host/CMakeFiles/ObjectDetection.dir/home/huawei/samples/Samples/InferObjectDetection/main.cpp.o
57%] Building CXX object device/CMakeFiles/Device.dir/home/huawei/samples/Samples/InferObjectDetection/ObjectDetectionEngine/ObjectDetectionEngine.cpp.o
71%] Building CXX object device/CMakeFiles/Device.dir/home/huawei/samples/Samples/InferObjectDetection/DecodeEngine/DecodeEngine.cpp.o
85%] Linking CXX executable ../ObjectDetection
85%] Built target ObjectDetection
[100%] Linking CXX shared library ../libDevice.so
[100%] Built target Device


模型转换成功!

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。