diff --git a/VisionSDK/YOLOv7Detection/CMakeLists.txt b/VisionSDK/YOLOv7Detection/CMakeLists.txt index 2deb1a25a31538290f416a1237f82f36fa1674a3..c40695f4b8e594d676a0490259edec0af1bb3ee6 100644 --- a/VisionSDK/YOLOv7Detection/CMakeLists.txt +++ b/VisionSDK/YOLOv7Detection/CMakeLists.txt @@ -26,4 +26,5 @@ target_link_libraries(sample mxbase yolov7postprocess opencv_world + cpprest ) \ No newline at end of file diff --git a/VisionSDK/YOLOv7Detection/README.md b/VisionSDK/YOLOv7Detection/README.md index b4432f90db500b8e2e32ec732a9318ba493389e5..dd206b49fd02b76c3a067228b94da6c3680036ab 100644 --- a/VisionSDK/YOLOv7Detection/README.md +++ b/VisionSDK/YOLOv7Detection/README.md @@ -1,25 +1,24 @@ # YOLOv7 模型推理参考样例 -## 1. 介绍 - -YOLOv7 目标检测后处理插件基于 Vision SDK 开发,对图片中的不同类目标进行检测。输入一幅图像,可以检测得到图像中大部分类别目标的位置。本方案基于 pytorch 版本原始 yolo7x.pt 模型所转换的 om 模型进行目标检测,默认模型包含 80 个目标类。 -### 1.1 支持的产品 - -本项目以昇腾310及310P芯片卡为主要的硬件平台。 +## 1. 介绍 +### 1.1 简介 -### 1.2 支持的版本 +YOLOv7 目标检测后处理插件基于 Vision SDK 开发,对图片中的不同类目标进行检测。输入一幅图像,可以检测得到图像中大部分类别目标的位置。本方案基于 pytorch 版本原始 yolo7x.pt 模型所转换的 om 模型进行目标检测,默认模型包含 80 个目标类。 -支持的SDK版本为 5.0.RC1, CANN 版本为 6.0.RC1。 +### 1.2 支持的产品 +本项目支持Atlas 300I pro、 Atlas 300V pro。 -### 1.3 软件方案介绍 -封装yolov7后处理方法到后处理插件中,通过编译yolov7postprocessor插件so, 将该插件应用到pipeline或者v2接口进行后处理计算。 +### 1.3 支持的版本 -#### 1.3.1 业务流程加图像预处理方案 +本样例配套的Vision SDK版本、CANN版本、Driver/Firmware版本如下所示: -Pytorch框架对yolov7模型推理时,前处理方案包括解码为BGR->等比缩放->中心补边->转换为RGB->标准化,main.cpp中通过在310P场景下通过dvpp及opencv对应方法进行了相应的处理,标准化的步骤在aipp配置项中完成。 +| Vision SDK版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 5.0.1 | 7.0.1.3 | 23.0.5 | + ### 1.4 代码目录结构与说明 @@ -45,12 +44,11 @@ Pytorch框架对yolov7模型推理时,前处理方案包括解码为BGR->等 ``` 注:yolov7.cfg中新增了一个配置项PADDING_TYPE用于区分补边的情况,若采用dvpp补边则填写0,采用opencv补边则填写1,默认为1。 -SampleYuv.pipeline中resize插件需要选用双线性插值的方式,需要根据310和310P环境填写interpolation的参数。310上需要设置"interpolation"为"1"。 +SampleYuv.pipeline中resize插件需要选用双线性插值的方式,需要根据Atlas 300I pro、 Atlas 300V pro填写interpolation的参数。 -## 2 环境依赖 +## 2 设置环境变量 -推荐系统为ubuntu 18.04,芯片环境310P: 在编译运行项目前,需要设置环境变量: @@ -73,13 +71,15 @@ SDK-path: Vision SDK 安装路径 ascend-toolkit-path: CANN 安装路径。 ``` -## 3. 模型转换 +## 3. 准备模型 + +**步骤1:** 模型下载。 关键依赖版本说明 PyTorch >=1.8.0 -请参考[链接](https://gitee.com/ascend/modelzoo-GPL/tree/master/built-in/ACL_Pytorch/Yolov7_for_Pytorch)对模型进行下载和转换为om。 -注意:由于main.cpp样例在310P环境下解码后的图片为BGR格式,因此使用aipp转换至om时,请将上述链接中的教程中 4. 使用aipp预处理 aipp_op中的rbuv_swap_switch项设置为true。 +请参考[链接](https://gitee.com/ascend/modelzoo-GPL/tree/master/built-in/ACL_Pytorch/Yolov7_for_Pytorch)下载模型并转换为ONNX模型,并使用下方提供的命令转换为OM模型。 +注意:由于main.cpp样例在Atlas 300I pro、 Atlas 300V pro下解码后的图片为BGR格式,因此使用aipp转换至om时,请将上述链接中的教程中的 4. 使用aipp预处理 aipp_op中的rbuv_swap_switch项设置为true。 转换完成后,将该模型放到model路径下。 转换为BGR输入参考 @@ -129,6 +129,7 @@ aipp_op { var_reci_chn_1: 0.0039215686274509803921568627451 var_reci_chn_2: 0.0039215686274509803921568627451 } + ``` atc转换模型命令参考 ``` @@ -146,12 +147,13 @@ atc --framework=5 --model=${onnx_model} --output={output_name} --input_format=NC **步骤1** 编译后处理插件so: -后处理插件编译步骤参考《Vision SDK用户指南》中 深入开发->推理模型后处理开发介绍->新框架模型后处理->编译,其中"samplepostprocess"和"SamplePostProcess.cpp"分别代表生成的后处理动态库名和生成后处理的目标文件,对应到yolov7则yolov7postprocess和Yolov7PostProcess.cpp, +进入plugin目录中,请创建文件夹build + 注意: 修改CMakeLists.txt中 ```set(PLUGIN_NAME "samplepostprocess")``` 一行中插件名称,为 ```set(PLUGIN_NAME "yolov7postprocess")``` 修改CMakeLists.txt中 ```add_library(${TARGET_LIBRARY} SHARED SamplePostProcess.cpp)``` 一行中cpp文件名称,为 ```add_library(${TARGET_LIBRARY} SHARED Yolov7PostProcess.cpp)``` -生成的so会在make install时被安装到${MX_SDK_HOME}/lib/modelpostprocessors/下,请确保该so文件权限为440。 +生成的so请移动至${MX_SDK_HOME}/lib/modelpostprocessors/下,请确保该so文件权限为440。 **步骤2** 放入待测图片。将一张图片放项目根路径下,命名为 test.jpg。 diff --git a/VisionSDK/YOLOv7Detection/main.cpp b/VisionSDK/YOLOv7Detection/main.cpp index 125cd9abf0349570e0c450239704311907344716..d18022057521e11112781316600b1a7e38020e75 100644 --- a/VisionSDK/YOLOv7Detection/main.cpp +++ b/VisionSDK/YOLOv7Detection/main.cpp @@ -29,7 +29,7 @@ #include "MxBase/MemoryHelper/MemoryHelper.h" #include "MxBase/DeviceManager/DeviceManager.h" #include "MxBase/Log/Log.h" -#include "Yolov7PostProcess.h" +#include "plugin/Yolov7PostProcess.h" using namespace MxBase; using namespace std; @@ -144,6 +144,7 @@ APP_ERROR PaddingProcess(ImageProcessor &imageProcessor, std::pair res LogError << "Failed to mallloc and copy dvpp memory."; return APP_ERR_ACL_BAD_COPY; } + std::shared_ptr pastedData((uint8_t*)resHostData.ptrData, resHostData.free); cv::Mat resizedHost(resizeImage.GetSize().height, resizeImage.GetSize().width, OPENCV_8UC3, resHostData.ptrData); cv::Rect roi = cv::Rect(0, 0, resizedWidth, resizedHeight); @@ -451,6 +452,9 @@ int main(int argc, char *argv[]) case '?': usage(); return 0; + default: + usage(); + return 0; } } if (pathMap.count("modelPath") <= 0 || pathMap.count("imgPath") <= 0 || pathMap.count("modelConfigPath") <= 0 || diff --git a/VisionSDK/YOLOv7Detection/plugin/CMakeLists.txt b/VisionSDK/YOLOv7Detection/plugin/CMakeLists.txt index 1af840a68d78a3624ddb02de5332fcff82cba346..61b5db71c3a7591b303a3ec330597d6b69277391 100644 --- a/VisionSDK/YOLOv7Detection/plugin/CMakeLists.txt +++ b/VisionSDK/YOLOv7Detection/plugin/CMakeLists.txt @@ -4,17 +4,18 @@ project(yolov7postprocess) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) add_definitions(-Dgoogle=mindxsdk_private) +set(MX_SDK_HOME $ENV{MX_SDK_HOME}) set(PLUGIN_NAME "yolov7postprocess") set(TARGET_LIBRARY ${PLUGIN_NAME}) -include_directories(${PROJECT_SOURCE_DIR}/../../include) -include_directories(${PROJECT_SOURCE_DIR}/../../opensource/include) -include_directories(${PROJECT_SOURCE_DIR}/../../opensource/include/gstreamer-1.0) -include_directories(${PROJECT_SOURCE_DIR}/../../opensource/include/glib-2.0) -include_directories(${PROJECT_SOURCE_DIR}/../../opensource/lib/glib-2.0/include) +include_directories(${MX_SDK_HOME}/include) +include_directories(${MX_SDK_HOME}/opensource/include) +include_directories(${MX_SDK_HOME}/opensource/include/gstreamer-1.0) +include_directories(${MX_SDK_HOME}/opensource/include/glib-2.0) +include_directories(${MX_SDK_HOME}/opensource/lib/glib-2.0/include) -link_directories(${PROJECT_SOURCE_DIR}/../../opensource/lib/) -link_directories(${PROJECT_SOURCE_DIR}/../../lib) +link_directories(${MX_SDK_HOME}/opensource/lib/) +link_directories(${MX_SDK_HOME}/lib) add_compile_options(-fPIC -std=c++11 -fstack-protector-all -Wl, -z,relro,-z,now,-z,noexecstack -s -pie) add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}") @@ -26,4 +27,4 @@ target_link_libraries(${TARGET_LIBRARY} glib-2.0 gstreamer-1.0 gobject-2.0 gstba target_link_libraries(${TARGET_LIBRARY} plugintoolkit mxpidatatype mxbase) target_link_libraries(${TARGET_LIBRARY} -Wl,-z,relro,-z,now,-z,noexecstack -s) -install(TARGETS ${TARGET_LIBRARY} PERMISSIONS OWNER_READ GROUP_READ LIBRARY DESTINATION ${PROJECT_SOURCE_DIR}/../../lib/modelpostprocessors) \ No newline at end of file +install(TARGETS ${TARGET_LIBRARY} PERMISSIONS OWNER_READ GROUP_READ LIBRARY DESTINATION ${MX_SDK_HOME}/lib/modelpostprocessors) \ No newline at end of file diff --git a/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.cpp b/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.cpp index d4c4f257423e1275348db08d8c69e5a12ade1c53..751c0b7e37f30616588199667634d6543bd5bef9 100644 --- a/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.cpp +++ b/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.cpp @@ -45,30 +45,6 @@ Yolov7PostProcess &Yolov7PostProcess::operator = (const Yolov7PostProcess &other return *this; } -APP_ERROR Yolov7PostProcess::Init(const std::map> &postConfig) -{ - LogDebug << "Start to Init Yolov7PostProcess. "; - APP_ERROR ret = ObjectPostProcessBase::Init(postConfig); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Fail to superInit in ObjectPostProcessorBase"; - return ret; - } - ret = configData_.GetFileValue("OBJECTNESS_THRESH", objectnessThresh_, 0.0f, 1.0f); - if (ret != APP_ERR_OK) { - LogWarn << GetError(ret) << "Fail to read OBJECTNESS_THRESH from config, default is :" << objectnessThresh_; - } - ret = configData_.GetFileValue("IOU_THRESH", iouThresh_, 0.0f, 1.0f); - if (ret != APP_ERR_OK) { - LogWarn << GetError(ret) << "Fail to read IOU_THRESH from config, default is :" << iouThresh_; - } - ret = configData_.GetFileValue("PADDING_TYPE", paddingType_, 0, 1); - if (ret != APP_ERR_OK) { - LogWarn << GetError(ret) << "Fail to read PADDING_TYPE from config, default is :" << paddingType_; - } - LogDebug << "End to Init Yolov7PostProcess. "; - return APP_ERR_OK; -} - APP_ERROR Yolov7PostProcess::Init(const std::map &postConfig) { LogDebug << "Start to Init Yolov7PostProcess. "; diff --git a/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.h b/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.h index 7cb4f96c5c2f4dec9db18d2c67759044354bc197..05b30b84d22f1e69cc2d72be98fd63eab5e08fdf 100644 --- a/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.h +++ b/VisionSDK/YOLOv7Detection/plugin/Yolov7PostProcess.h @@ -33,7 +33,6 @@ public: Yolov7PostProcess &operator=(const Yolov7PostProcess &other); - SDK_DEPRECATED_FOR() APP_ERROR Init(const std::map> &postConfig) override; APP_ERROR Init(const std::map &postConfig) override; APP_ERROR DeInit() override; diff --git a/VisionSDK/YOLOv7Detection/run.sh b/VisionSDK/YOLOv7Detection/run.sh index 79b314a20e02c9adc2f72df7a4ed8f99f4cf9b95..02a810d916f9e8544e0baf45cbe7937f09ee2df4 100644 --- a/VisionSDK/YOLOv7Detection/run.sh +++ b/VisionSDK/YOLOv7Detection/run.sh @@ -1,4 +1,18 @@ #!/bin/bash +cd plugin +rm -fr build +mkdir -p build +cd build +cmake .. +make -j || { + ret=$? + echo "Failed to build." + exit ${ret} +} +make install +cd .. +cd .. + rm -fr build mkdir -p build cd build diff --git a/contrib/OpenCVPlugin/README.md b/contrib/OpenCVPlugin/README.md index 93ad541e2d1d87348209ea815a50cb8750109f4c..19cf0f6491d6803f7c07bfd5e8199eb2672b867e 100644 --- a/contrib/OpenCVPlugin/README.md +++ b/contrib/OpenCVPlugin/README.md @@ -12,7 +12,7 @@ ### 1.1 支持的产品 -本项目以昇腾Atlas310卡为主要的硬件平台。 +本项目支持x86_64 Atlas 300I (型号3010) 和 arm Atlas 300I (型号3000)。 ### 1.2 支持的版本