当前位置:网站首页>华为Ascend910运行yolov3教程
华为Ascend910运行yolov3教程
2022-07-17 11:18:00 【花花少年】
一、关键步骤
下载源码: ACL_YOLOV3
1.1 安装opencv
安装编译好的opencv静态链接库。
1.1.1 下载
链接:https://pan.baidu.com/s/1sdCsP3_NU48Nz8PYw-wpkg
提取码:1234或者
链接: https://pan.baidu.com/s/1Z8sGoSI3eqUfime9aF5wSQ 密码: r80o
1.1.2 解压
解压opencv压缩包到指定目录,例如:/home/ma-user/work/opencv-4.5.1。
1.2 修改CMakeLists.txt
# 修改OpenCV_DIR路径
# OpenCV_DIR目录包含OpenCVConfig.cmake
set(OpenCV_DIR /home/ma-user/work/opencv-4.5.1/lib/cmake/opencv4)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
if(${OPENCV_FOUND})
message(STATUS "OpenCV version: ${OpenCV_VERSION}")
message(STATUS "OpenCV include path: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
endif()
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
# 修改ACL_PATH路径
set(ACL_PATH /home/ma-user/Ascend/ascend-toolkit/latest)
1.3 模型转换
1.3.1 模型下载
https://pan.baidu.com/s/1yiCrnmsOm0hbweJBiiUScQ
或者
链接:https://pan.baidu.com/s/1xZ2UuQAchtnpVrcCO6zQPA
提取码:1234
1.3.2 修改 prototxt 配置文件
完全按照模板修改:YOLOv3网络模型prototxt修改
upsample算子upsample_param属性参数修改;
修改两处。
新增三个Yolo算子;
最后一层增加YoloV3DetectionOutput算子;
新增输入;
原输入:
input: "data" input_shape { dim: 1 dim: 3 dim: 416 dim: 416 }新增输入:
input: "img_info" input_shape { dim: 1 dim: 4 }
1.3.3 修改 aipp 配置文件
不修改。
1.3.4 模型转换
cd yolov3
atc --model=./yolov3.prototxt \
--weight=./yolov3.caffemodel \
--framework=0 \
--output=./yolov3_aipp \
--output_type=FP32 \
--soc_version=Ascend910 \
--insert_op_conf=./aipp_yolov3.cfg
1.4 运行成功
[[email protected] acl_yolov3]$ ./ACL_YOLOV3 ./data/model/yolov3_aipp.om ./test.jpg
acl init successfully
Create context successfully
set context successfully
Create stream successfully
ModelProcess:Begin to init instance.
finish init AclProcess
ModelProcess:Begin to inference.
begin postprocess
The number of output buffers of yolov3 model is 2
Object detected number is 1
#Obj0, box(427.5, 424.25, 1513, 851.5) confidence: 1 lable: 2
model run success!
cost time : 18.924ms
ModelProcess:Begin to deinit instance.
ModelProcess:Finished deinit instance.
all tasks in stream done
Destroy Stream successfully
Destroy Context successfully
acl deinit successfully
二、FAQ
Q:缺少-fPIC
/usr/bin/ld: CMakeFiles/ACL_YOLOV3.dir/main.cpp.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `[email protected]@GLIBCXX_3.4' which may bind externally can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: CMakeFiles/ACL_YOLOV3.dir/main.cpp.o(.text+0x2c): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `[email protected]@GLIBCXX_3.4'
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ACL_YOLOV3.dir/build.make:144: ../ACL_YOLOV3] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/ACL_YOLOV3.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
解决办法:
修改CMakeLists.txt
add_definitions(-fPIC)
Q:缺少 dlsym
/usr/bin/ld: /home/ma-user/work/opencv-4.5.1/lib/libopencv_core.a(filesystem.cpp.obj): in function `cv::plugin::impl::DynamicLib::getSymbol(char const*) const': filesystem.cpp:(.text._ZNK2cv6plugin4impl10DynamicLib9getSymbolEPKc+0x8): undefined reference to `dlsym' /usr/bin/ld: /home/ma-user/work/opencv-4.5.1/lib/libopencv_core.a(filesystem.cpp.obj): in function `cv::plugin::impl::DynamicLib::libraryLoad(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
filesystem.cpp:(.text._ZN2cv6plugin4impl10DynamicLib11libraryLoadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x3c): undefined reference to `dlopen' /usr/bin/ld: /home/ma-user/work/opencv-4.5.1/lib/libopencv_core.a(filesystem.cpp.obj): in function `cv::plugin::impl::DynamicLib::libraryRelease()': filesystem.cpp:(.text._ZN2cv6plugin4impl10DynamicLib14libraryReleaseEv+0x3b4): undefined reference to `dlclose'
/usr/bin/ld: /home/ma-user/work/opencv-4.5.1/lib/libopencv_core.a(datafile.cpp.obj): in function `cv::utils::getModuleLocation(void const*)': datafile.cpp:(.text._ZN2cv5utilsL17getModuleLocationEPKv+0x2c): undefined reference to `dladdr' /usr/bin/ld: /home/ma-user/work/opencv-4.5.1/lib/libopencv_core.a(datafile.cpp.obj): in function `cv::utils::getBinLocation(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
datafile.cpp:(.text._ZN2cv5utils14getBinLocationERNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x30): undefined reference to `dladdr'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ACL_YOLOV3.dir/build.make:144: ../ACL_YOLOV3] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/ACL_YOLOV3.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
解决办法:
修改CMakeLists.txt,添加dl
target_link_libraries(${PROJECT_NAME} ascendcl ${OpenCV_LIBS} pthread -Wl,-z,relro,-z,now,-z,noexecstack -pie -s stdc++)
修改为
target_link_libraries(${PROJECT_NAME} ascendcl ${OpenCV_LIBS} pthread -Wl,-z,relro,-z,now,-z,noexecstack -pie -s stdc++ dl)
Q:缺少acl.json文件
[[email protected] acl_yolov3]$ ./ACL_YOLOV3 ./data/model/yolov3_aipp.om ./test.jpg
Failed to init acl, ret = 100003
AclProcess Init faild.
some tasks in stream not done, ret = 107002
all tasks in stream done
Destroy Stream faild, ret = 100000
Destroy Stream successfully
Destroy Context faild, ret = 100000
Destroy Context successfully
acl deinit successfully
错误原因:
缺少acl.json文件,导致aclInit初始化失败
解决办法:
aclError ret = aclprocess.Init(0,"./data/acl.json",argv[1]);
改为
aclError ret = aclprocess.Init(0,"",argv[1]);
Q:保存图片无法显示
错误原因:
由于采用opencv静态链接库,导致jpg编码器无法使用(功能不完整)
解决办法:
使用png格式保存图片
imwrite("result.jpg",img);
改为
imwrite("result.png",img);
边栏推荐
- FAW Toyota Asia lion's first product refresh
- Series operation of vector container (detailed explanation)
- vim诡异的未知函数0
- 一汽丰田亚洲狮首次产品焕新
- Packet knowledge
- Chapter 4 - consistency of first-order multi-agent systems - > consistency of continuous time systems with time delays
- PTA 1037 在霍格沃茨找零钱
- 【C语言】浅涉第一个C语言程序及数据类型
- Chapter 13 set/ multiset of STL
- 【565. 数组嵌套】
猜你喜欢

第4章-一阶多智体系统一致性 -> 切换拓扑系统一致性

ES Restful操作
![[C language] user defined type elementary knowledge points](/img/73/d225a0d93d11e1efd5b2446996e1fa.png)
[C language] user defined type elementary knowledge points
[email protected](Fe)复合纳米材料"/>金属有机骨架材料/聚合物复合材料ZIF-8/P(TDA-co-HDA)|氧化锌[email protected](Fe)复合纳米材料

CLWY权限管理(一)--- 项目搭建

Componentized advanced -- slot

rhcsa 第二天 7.15

Chapter 4 - consistency of first-order multi-agent systems - > consistency of continuous time systems with time delays

Build a server environment with node+express

闲谈工业企业全厂信息化规划
随机推荐
D. Mark and Lightbulbs
Chapter VIII vector of STL
氮杂环分子改性UiO-66-NH2|聚乙烯亚胺改性UiO-66-NH2|[email protected]@ZIF67纳米材料
数据库概述
【565. 数组嵌套】
node+express搭建服务器环境
Part I - Fundamentals of C language_ 4. Procedure flow structure
es索引、类型(mapping)、文档、ik分词器
How to deploy agent separately on the monitoring host -- wgcloud
Rhcsa the next day 7.15
Redis cache avalanche
Mysqldump full recovery to another new instance, and then perform flush privileges analysis
R language ggplot2 visual faceting: ggplot2 visualizes facets and removes the border lines between facets and the gap between facets (remove spacing between panels)
流量排名100W网站
UiO-66-(COOH)2改性聚酰胺纳滤膜|ZIF-8/PVP复合纳米纤维膜|UiO-66-NH2改性聚酰胺纳滤膜
Mutual access between components
【C语言】字符串、转义字符及注释
PTA 1037 在霍格沃茨找零钱
565. Array nesting / Sword finger offer II 001 Integer division
第九章 STL 之 deque