From d1b6da0206e5fffde699a03e576c7166b7db57a2 Mon Sep 17 00:00:00 2001 From: e <942295643@qq.com> Date: Mon, 29 Jan 2024 11:12:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=8F=82=E8=80=83=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/human_segmentation/README.md | 48 ++++++------------- contrib/human_segmentation/main.cpp | 34 +++++++++++-- contrib/mxBase_wheatDetection/README.md | 30 +++--------- contrib/mxBase_wheatDetection/main.cpp | 6 +++ .../yolov5Detection/Yolov5Detection.cpp | 9 ++-- .../yolov5Detection/Yolov5Detection.h | 2 +- .../yolov5PostProcess/Yolov5PostProcess.cpp | 2 +- .../yolov5PostProcess/Yolov5PostProcess.h | 4 +- contrib/yunet/README.md | 16 +++---- contrib/yunet/plugin/YunetPostProcess.cpp | 2 +- contrib/yunet/plugin/YunetPostProcess.h | 2 +- contrib/yunet/plugin2/KPYunetPostProcess.cpp | 2 +- contrib/yunet/plugin2/KPYunetPostProcess.h | 2 +- .../yunet/plugin3/TotalYunetPostProcess.cpp | 2 +- contrib/yunet/plugin3/TotalYunetPostProcess.h | 2 +- 15 files changed, 81 insertions(+), 82 deletions(-) diff --git a/contrib/human_segmentation/README.md b/contrib/human_segmentation/README.md index 2e4816761..f9c2cee7b 100644 --- a/contrib/human_segmentation/README.md +++ b/contrib/human_segmentation/README.md @@ -17,12 +17,12 @@ ``` ## 3 依赖 -| 软件名称 | 版本 | -| :--------: | :------: | -|ubantu 18.04|18.04.1 LTS | -|MindX SDK|2.0.4| -|C++| 11.0| -|opencv2| | +| 软件名称 | 版本 | +| :--------: |:-----------:| +|ubantu 18.04| 18.04.1 LTS | +|MindX SDK| 5.0.0 | +|C++| 11.0 | +|opencv2| | ## 4 模型转换 @@ -35,20 +35,13 @@ 在pb文件所在目录下执行以下命令 ``` -#设置环境变量(请确认install_path路径是否正确) -#Set environment PATH (Please confirm that the install_path is correct). +# 设置CANN环境变量(请确认install_path路径是否正确) +# Set environment PATH (Please confirm that the install_path is correct). +# ascend-toolkit-path: CANN 安装路径 +. ${ascend-toolkit-path}/set_env.sh -export install_path=/usr/local/Ascend/ascend-toolkit/latest - -export PATH=/usr/local/python3.9.2/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - -export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg - -export LD_LIBRARY_PATH=${install_path}/atc/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp - -#执行,转换human_segmentation.pb模型 -#Execute, transform 转换human_segmentation.pb model. +# 执行,转换human_segmentation.pb模型 +# Execute, transform 转换human_segmentation.pb model. atc --input_shape="input_rgb:1,512,512,3" --input_format=NHWC --output=human_segmentation --soc_version=Ascend310 --insert_op_conf=./insert_op.cfg --framework=3 --model=./human_segmentation.pb ``` @@ -69,20 +62,9 @@ https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/tutorials/%E5 2. 配置 ``` -# 执行如下命令,打开.bashrc文件 -vi .bashrc -# 在.bashrc文件中添加以下环境变量 -MX_SDK_HOME=${SDK安装路径} - -LD_LIBRARY_PATH=${MX_SDK_HOME}/lib:${MX_SDK_HOME}/opensource/lib:${MX_SDK_HOME}/opensource/lib64:${FFMPEG_HOME}/lib:/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:/usr/local/Ascend/driver/lib64/ - -GST_PLUGIN_SCANNER=${MX_SDK_HOME}/opensource/libexec/gstreamer-1.0/gst-plugin-scanner - -GST_PLUGIN_PATH=${MX_SDK_HOME}/opensource/lib/gstreamer-1.0:${MX_SDK_HOME}/lib/plugins - -# 保存退出.bashrc文件 -# 执行如下命令使环境变量生效 -source ~/.bashrc +# 设置MindXSDK环境变量 +# SDK-path: mxVision SDK 安装路径 +. ${SDK-path}/set_env.sh #查看环境变量 env diff --git a/contrib/human_segmentation/main.cpp b/contrib/human_segmentation/main.cpp index d0812567b..510b66a23 100644 --- a/contrib/human_segmentation/main.cpp +++ b/contrib/human_segmentation/main.cpp @@ -19,12 +19,18 @@ #include "MxBase/MemoryHelper/MemoryHelper.h" #include "MxStream/StreamManager/MxStreamManager.h" #include "MxBase/Tensor/TensorBase/TensorBase.h" -#include "MxBase/CV/Segmentation/DrawPixels.h" #include "MxBase/PostProcessBases/SemanticSegPostProcessBase.h" #define INPUT_MODEL_HEIGHT 512 #define INPUT_MODEL_WIDTH 512 #define OUTPUT_MODEL_WIDTH 512 +#define CHANNEL0 0 +#define CHANNEL1 1 +#define CHANNEL2 2 +#define RCHANNEL_MUL 34527 +#define GCHANNEL_MUL 78997 +#define BCHANNEL_MUL 12347 +#define COMPRESSION_LEVEL 9 // Read the information in the file static APP_ERROR readfile(const std::string& filePath, MxStream::MxstDataInput& dataBuffer) { @@ -152,6 +158,28 @@ void semanticsegoutput(const std::vector& tensors, } } +APP_ERROR DrawPixelsRGB(const std::vector>& pixels, std::string outputPath) +{ + if (pixels.empty() || pixels[0].empty()) { + LogError << "pixels is empty; Draw image failed."; + return APP_ERR_INPUT_NOT_MATCH; + } + cv::Mat mat(pixels.size(), pixels[0].size(), CV_8UC3); + for (int i = 0; i < mat.rows; ++i) { + for (int j = 0; j < mat.cols; ++j) { + int pixel = pixels[i][j]; + mat.at(i, j)[CHANNEL0] = (pixel * RCHANNEL_MUL) % (UINT8_MAX + 1); + mat.at(i, j)[CHANNEL1] = (pixel * GCHANNEL_MUL) % (UINT8_MAX + 1); + mat.at(i, j)[CHANNEL2] = (pixel * BCHANNEL_MUL) % (UINT8_MAX + 1); + } + } + std::vector compressionParams; + compressionParams.push_back(cv::IMWRITE_PNG_COMPRESSION); + compressionParams.push_back(COMPRESSION_LEVEL); + imwrite(outputPath, mat, compressionParams); + return APP_ERR_OK; +} + // Mask diagram generation APP_ERROR draw(const std::vector& tensors, std::vector& semanticSegInfos, @@ -165,7 +193,7 @@ APP_ERROR draw(const std::vector& tensors, for (uint32_t i = 0; i < semanticSegInfos.size(); i++) { std::ostringstream outputPath; outputPath << "./data/mask_" << inputPicname; - MxBase::DrawPixelsRGB(semanticSegInfos[i].pixels, outputPath.str()); + DrawPixelsRGB(semanticSegInfos[i].pixels, outputPath.str()); } } return APP_ERR_OK; @@ -193,7 +221,7 @@ void image_fusion(std::string filename,std::string maskname,std::string &inputP int main(int argc, char* argv[]) { // Enter the image name, path - std::string inputPicname = "test.jpeg"; + std::string inputPicname = "test.jpg"; std::string inputPicPath = "./data/"+inputPicname; unsigned long idx = inputPicname.find(".jpg"); diff --git a/contrib/mxBase_wheatDetection/README.md b/contrib/mxBase_wheatDetection/README.md index bccb0c9b0..ea13c3645 100644 --- a/contrib/mxBase_wheatDetection/README.md +++ b/contrib/mxBase_wheatDetection/README.md @@ -88,14 +88,10 @@ python export.py --weights best_v3.pt --img 416 --batch 1 --simplify **步骤3** 执行模型转换命令 (1) 配置环境变量 -#### 设置环境变量(请确认install_path路径是否正确) -#### Set environment PATH (Please confirm that the install_path is correct). +#### 设置CANN环境变量(请确认install_path路径是否正确) +#### Set environment PATH (Please confirm that the install_path is correct), ascend-toolkit-path为CANN安装路径 ```c -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.9.2/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp +. ${ascend-toolkit-path}/set_env.sh ``` (2) 转换模型 @@ -139,13 +135,9 @@ atc --model=./best_v3_t.onnx --framework=5 --output=./onnx_best_v3 --soc_version **步骤2** -ASCEND_HOME Ascend安装的路径,一般为/usr/local/Ascend -LD_LIBRARY_PATH 指定程序运行时依赖的动态库查找路径,包括ACL,开源软件库,libmxbase.so以及libyolov3postprocess.so的路径 +设置MindXSDK 环境变量,SDK-path为mxVision SDK 安装路径 ``` -export ASCEND_HOME=/usr/local/Ascend -export ASCEND_VERSION=nnrt/latest -export ARCH_PATTERN=. -export LD_LIBRARY_PATH=${MX_SDK_HOME}/lib/modelpostprocessors:${MX_SDK_HOME}/lib:${MX_SDK_HOME}/opensource/lib:${MX_SDK_HOME}/opensource/lib64:/usr/local/Ascend/driver/lib64:/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:${LD_LIBRARY_PATH} +. ${SDK-path}/set_env.sh ``` **步骤3** @@ -164,14 +156,6 @@ cd 到mxBase_wheatDetection目录下 ./mxBase_wheatDetection ./test/ ``` -## 精度测试 +## 性能测试 -使用(https://github.com/Cartucho/mAP)进行map计算,需要参考readme将推理结果数据以下方式转换并存储为txt - -``` - -``` - -并将相关txt保存至input/detection-results/文件夹,对标签进行相同转换并保存至 input/ground-truth/文件夹。 -随后执行python main.py以计算map并生成相关绘图。 -使用GWHD2020数据集训练集进行测试,map为0.8,性能为14FPS. \ No newline at end of file +使用GWHD2020数据集训练集进行测试,性能为15FPS。 \ No newline at end of file diff --git a/contrib/mxBase_wheatDetection/main.cpp b/contrib/mxBase_wheatDetection/main.cpp index 859af13cd..fa958950c 100644 --- a/contrib/mxBase_wheatDetection/main.cpp +++ b/contrib/mxBase_wheatDetection/main.cpp @@ -102,17 +102,23 @@ int main(int argc, char* argv[]) return ret; } get_files(argv[1], files); + float totalTime = 0; for (uint32_t i = 0; i < files.size(); i++) { // 推理业务开始 std::string imgPath = files[i]; + auto start = std::chrono::steady_clock::now(); ret = yolov5->Process(imgPath); + auto end = std::chrono::steady_clock::now(); if (ret != APP_ERR_OK) { LogError << "Yolov5Detection process failed, ret=" << ret << "."; yolov5->DeInit(); return ret; } + totalTime = totalTime + std::chrono::duration(end - start).count() / 1000; } + auto fps = files.size() / totalTime; + LogInfo << "Process FPS: " << fps; yolov5->DeInit(); LogInfo << "Project end!!!!"; return APP_ERR_OK; diff --git a/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.cpp b/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.cpp index aded23585..fe0b7b09c 100644 --- a/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.cpp +++ b/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.cpp @@ -62,7 +62,7 @@ APP_ERROR Yolov5Detection::LoadLabels(const std::string &labelPath, std::map> &config) { + std::map &config) { MxBase::ConfigData g_config_data; const std::string checkTensor = initParam.checkTensor ? "true" : "false"; g_config_data.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); @@ -78,8 +78,8 @@ void Yolov5Detection::SetYolov5PostProcessConfig(const InitParam &initParam, g_config_data.SetJsonValue("CHECK_MODEL", checkTensor); auto jsonStr = g_config_data.GetCfgJson().serialize(); - config["postProcessConfigContent"] = std::make_shared(jsonStr); - config["labelPath"] = std::make_shared(initParam.labelPath); + config["postProcessConfigContent"] = jsonStr; + config["labelPath"] = initParam.labelPath; } APP_ERROR Yolov5Detection::Init(const InitParam &initParam) { @@ -107,7 +107,7 @@ APP_ERROR Yolov5Detection::Init(const InitParam &initParam) { return ret; } - std::map> config; + std::map config; SetYolov5PostProcessConfig(initParam, config); // 初始化Yolov5后处理对象 post_ = std::make_shared(); @@ -310,7 +310,6 @@ APP_ERROR Yolov5Detection::WriteResult(MxBase::TensorBase &tensor, green, thickness); } // 把Mat类型的图像矩阵保存为图像到指定位置。 - cv::imwrite(newSavePath, imgBgr); return APP_ERR_OK; diff --git a/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.h b/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.h index 337d79b17..cca708957 100644 --- a/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.h +++ b/contrib/mxBase_wheatDetection/yolov5Detection/Yolov5Detection.h @@ -54,7 +54,7 @@ protected: APP_ERROR WriteResult(MxBase::TensorBase &tensor, const std::vector> &objInfos, const std::string &imgPath); - void SetYolov5PostProcessConfig(const InitParam &initParam, std::map> &config); + void SetYolov5PostProcessConfig(const InitParam &initParam, std::map &config); private: std::shared_ptr dvppWrapper_; // 封装DVPP基本编码、解码、扣图功能 std::shared_ptr model_; // 模型推理功能处理 diff --git a/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.cpp b/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.cpp index fa5803a5a..e67c401c8 100644 --- a/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.cpp +++ b/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.cpp @@ -54,7 +54,7 @@ Yolov5PostProcess &Yolov5PostProcess::operator=(const Yolov5PostProcess &other) return *this; } -APP_ERROR Yolov5PostProcess::Init(const std::map> &postConfig) { +APP_ERROR Yolov5PostProcess::Init(const std::map &postConfig) { APP_ERROR ret = ObjectPostProcessBase::Init(postConfig); if (ret != APP_ERR_OK) { LogError << GetError(ret) << "Fail to superInit in ObjectPostProcessBase."; diff --git a/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.h b/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.h index 0f775c352..9d806702f 100644 --- a/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.h +++ b/contrib/mxBase_wheatDetection/yolov5PostProcess/Yolov5PostProcess.h @@ -52,7 +52,7 @@ public: Yolov5PostProcess &operator=(const Yolov5PostProcess &other); - APP_ERROR Init(const std::map> &postConfig) override; + APP_ERROR Init(const std::map &postConfig) override; APP_ERROR DeInit() override; @@ -61,7 +61,7 @@ public: const std::vector &resizedImageInfos = {}, const std::map> ¶mMap = {}) override; protected: - bool IsValidTensors(const std::vector &tensors) const override; + bool IsValidTensors(const std::vector &tensors) const; void ObjectDetectionOutput(const std::vector &tensors, std::vector> &objectInfos, diff --git a/contrib/yunet/README.md b/contrib/yunet/README.md index fb6944a70..216cfe967 100644 --- a/contrib/yunet/README.md +++ b/contrib/yunet/README.md @@ -10,9 +10,9 @@ yunet基于MindXSDK开发,在昇腾芯片上进行人脸检测,并实现可 ### 1.2 支持的版本 -CANN:7.0.RC1 +CANN:7.0.0 -SDK:mxVision 5.0.RC3(可通过cat SDK目录下的 version.info 查看) +SDK:mxVision 5.0.0(可通过cat SDK目录下的 version.info 查看) ### 1.3 软件方案介绍 @@ -95,17 +95,17 @@ SDK:mxVision 5.0.RC3(可通过cat SDK目录下的 version.info 查看) 推荐系统为ubuntu 18.04,环境软件和版本如下: -| 软件名称 | 版本 | 说明 | 获取方式 | -| ------------------- | ----- | ----------------------------- | :-------------------------------------------------------- | -| MindX SDK | 5.0.RC3 | mxVision软件包 | [链接](https://www.hiascend.com/software/Mindx-sdk) | +| 软件名称 | 版本 | 说明 | 获取方式 | +| ------------------- |-------| ----------------------------- | :-------------------------------------------------------- | +| MindX SDK | 5.0.0 | mxVision软件包 | [链接](https://www.hiascend.com/software/Mindx-sdk) | | ubuntu | 18.04 | 操作系统 | 请上ubuntu官网获取 | -| Ascend-CANN-toolkit | 7.0.RC1 | Ascend-cann-toolkit开发套件包 | [链接](https://www.hiascend.com/software/cann/commercial) | +| Ascend-CANN-toolkit | 7.0.0 | Ascend-cann-toolkit开发套件包 | [链接](https://www.hiascend.com/software/cann/commercial) | 在编译运行项目前,需要设置环境变量: -MindSDK 环境变量: +MindXSDK 环境变量: ``` . ${SDK-path}/set_env.sh @@ -232,7 +232,7 @@ make -j make install ```` -如果权限问题,`cd`到MindSDK安装路径的`lib/modelpostprocessors`目录,将`libyunetpostprocess.so`的权限更改为`640`。 +将生成的模型后处理so拷贝至MindXSDK安装路径的`lib/modelpostprocessors`目录。如果权限问题,`cd`到MindXSDK安装路径的`lib/modelpostprocessors`目录,将`libyunetpostprocess.so`的权限更改为`640`。 对于`plugin2`、`plugin3`目录也同样处理。 diff --git a/contrib/yunet/plugin/YunetPostProcess.cpp b/contrib/yunet/plugin/YunetPostProcess.cpp index 14d15de71..236c30585 100644 --- a/contrib/yunet/plugin/YunetPostProcess.cpp +++ b/contrib/yunet/plugin/YunetPostProcess.cpp @@ -45,7 +45,7 @@ namespace MxBase { return *this; } - APP_ERROR YunetPostProcess::Init(const std::map >& postConfig) + APP_ERROR YunetPostProcess::Init(const std::map & postConfig) { LogDebug << "Start to Init YunetPostProcess."; APP_ERROR ret = ObjectPostProcessBase::Init(postConfig); diff --git a/contrib/yunet/plugin/YunetPostProcess.h b/contrib/yunet/plugin/YunetPostProcess.h index e08d8fc7d..99e23ef66 100644 --- a/contrib/yunet/plugin/YunetPostProcess.h +++ b/contrib/yunet/plugin/YunetPostProcess.h @@ -39,7 +39,7 @@ namespace MxBase { YunetPostProcess& operator=(const YunetPostProcess& other); - APP_ERROR Init(const std::map >& postConfig) override; + APP_ERROR Init(const std::map & postConfig) override; APP_ERROR DeInit() override; diff --git a/contrib/yunet/plugin2/KPYunetPostProcess.cpp b/contrib/yunet/plugin2/KPYunetPostProcess.cpp index 0cb15dd5e..dd66886b8 100644 --- a/contrib/yunet/plugin2/KPYunetPostProcess.cpp +++ b/contrib/yunet/plugin2/KPYunetPostProcess.cpp @@ -45,7 +45,7 @@ namespace MxBase { return *this; } - APP_ERROR KPYunetPostProcess::Init(const std::map >& postConfig) + APP_ERROR KPYunetPostProcess::Init(const std::map & postConfig) { LogDebug << "Start to Init KPYunetPostProcess."; APP_ERROR ret = KeypointPostProcessBase::Init(postConfig); diff --git a/contrib/yunet/plugin2/KPYunetPostProcess.h b/contrib/yunet/plugin2/KPYunetPostProcess.h index 57226481c..88496062b 100644 --- a/contrib/yunet/plugin2/KPYunetPostProcess.h +++ b/contrib/yunet/plugin2/KPYunetPostProcess.h @@ -43,7 +43,7 @@ namespace MxBase { KPYunetPostProcess& operator=(const KPYunetPostProcess& other); - APP_ERROR Init(const std::map >& postConfig) override; + APP_ERROR Init(const std::map & postConfig) override; APP_ERROR DeInit() override; diff --git a/contrib/yunet/plugin3/TotalYunetPostProcess.cpp b/contrib/yunet/plugin3/TotalYunetPostProcess.cpp index c4cc7e1c0..1c5440c0d 100644 --- a/contrib/yunet/plugin3/TotalYunetPostProcess.cpp +++ b/contrib/yunet/plugin3/TotalYunetPostProcess.cpp @@ -47,7 +47,7 @@ namespace MxBase { return *this; } - APP_ERROR TotalYunetPostProcess::Init(const std::map >& postConfig) + APP_ERROR TotalYunetPostProcess::Init(const std::map & postConfig) { LogDebug << "Start to Init TotalYunetPostProcess."; APP_ERROR ret = ObjectPostProcessBase::Init(postConfig); diff --git a/contrib/yunet/plugin3/TotalYunetPostProcess.h b/contrib/yunet/plugin3/TotalYunetPostProcess.h index 31d915836..60753ed03 100644 --- a/contrib/yunet/plugin3/TotalYunetPostProcess.h +++ b/contrib/yunet/plugin3/TotalYunetPostProcess.h @@ -39,7 +39,7 @@ namespace MxBase { TotalYunetPostProcess& operator=(const TotalYunetPostProcess& other); - APP_ERROR Init(const std::map >& postConfig) override; + APP_ERROR Init(const std::map & postConfig) override; APP_ERROR DeInit() override; -- Gitee