diff --git a/contrib/EdgeDetectionPicture/CMakeLists.txt b/contrib/EdgeDetectionPicture/CMakeLists.txt index 3928c17d701784863e6d9b84789407f27010d495..8baf9777d5ea833b427e95d9a4026a03e19d60cc 100644 --- a/contrib/EdgeDetectionPicture/CMakeLists.txt +++ b/contrib/EdgeDetectionPicture/CMakeLists.txt @@ -6,7 +6,7 @@ include_directories(./rcfDetection) file(GLOB_RECURSE RCF_POSTPROCESS ${PROJECT_SOURCE_DIR}/rcfPostProcess/*cpp) file(GLOB_RECURSE RCF_DETECTION ${PROJECT_SOURCE_DIR}/rcfDetection/*cpp) set(TARGET edge_detection_picture) -add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -s -pie -Wall) +add_compile_options(-std=c++14 -fPIE -fstack-protector-all -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -s -pie -Wall) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0 -Dgoogle=mindxsdk_private) set(MX_SDK_HOME "$ENV{MX_SDK_HOME}") diff --git a/contrib/EdgeDetectionPicture/License b/contrib/EdgeDetectionPicture/License deleted file mode 100644 index 841b92923ccdd18807f421c2a17e19599aa2fbc6..0000000000000000000000000000000000000000 --- a/contrib/EdgeDetectionPicture/License +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright(C) 2021. Huawei Technologies Co.,Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/contrib/EdgeDetectionPicture/README.md b/contrib/EdgeDetectionPicture/README.md index e00f69a20be355c1a3d718c2da7393cdb64a5338..750c625d6eb5487d6dbcc191e1f3ba75b5ba303f 100644 --- a/contrib/EdgeDetectionPicture/README.md +++ b/contrib/EdgeDetectionPicture/README.md @@ -1,19 +1,29 @@ - # RCF模型边缘检测 ## 1 介绍 -本开发样例是基于mxBase开发的端到端推理的C++应用程序,可在昇腾芯片上进行 图像边缘提取,并把可视化结果保存到本地。 -其中包含Rcf模型的后处理模块开发。 主要处理流程为: Init > ReadImage >Resize > Inference >PostProcess >DeInit +### 1.1 简介 +本开发样例是基于mxBase开发的端到端推理的C++应用程序,可进行图像边缘提取,并把可视化结果保存到本地。 其中包含Rcf模型的后处理模块开发。 + +主要处理流程为: + +Init > ReadImage >Resize > Inference >PostProcess >DeInit + +### 1.2 支持的产品 + +本项目支持昇腾Atlas 300I pro、 Atlas 300V pro + +### 1.3 支持的版本 +本样例配套的MxVision版本、CANN版本、Driver/Firmware版本如下所示: -#### 1.1 支持的产品 -昇腾310(推理) +| MxVision版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | -#### 1.2 支持的版本 -本样例配套的CANN版本为7.0.0,MindX SDK版本为5.0.0 -MindX SDK安装前准备可参考《用户指南》,[安装教程](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/quickStart/1-1%E5%AE%89%E8%A3%85SDK%E5%BC%80%E5%8F%91%E5%A5%97%E4%BB%B6.md) +### 1.4 三方依赖 +无 -#### 1.3 代码目录结构与说明 -本sample工程名称为EdgeDetectionPicture,工程目录如下图所示: +### 1.5 代码目录结构说明 +本工程名称为EdgeDetectionPicture,工程目录如下图所示: ``` . @@ -28,123 +38,50 @@ MindX SDK安装前准备可参考《用户指南》,[安装教程](https://git ├── build.sh ├── main.cpp ├── README.md -├── CMakeLists.txt -└── License -``` - -## 2 环境依赖 -环境依赖软件和版本如下表: - - - -| 软件 | 版本 | 说明 | 获取方式 | -| ------------------- | ------------ | ----------------------------- | ------------------------------------------------------------ | -| mxVision | 5.0.0 | mxVision软件包 | [链接](https://www.hiascend.com/software/Mindx-sdk) | -| Ascend-CANN-toolkit | 7.0.0 | Ascend-cann-toolkit开发套件包 | [链接](https://www.hiascend.com/software/cann/commercial) | -| 操作系统 | Ubuntu 18.04 | 操作系统 | Ubuntu官网获取 | - -在编译运行项目前,需要设置环境变量: - -- 环境变量介绍 - - ``` - . {cann_install_path}/ascend-toolkit/set_env.sh - . {sdk_install_path}/mxVision/set_env.sh - - ``` - - - -## 3 模型转换 - -**步骤1** 模型获取 -下载RCF模型 。[下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/EdgeDetectionPicture/model.zip) - -**步骤2** 模型存放 -将获取到的RCF模型rcf.prototxt文件和rcf_bsds.caffemodel文件放在edge_detection_picture/model下 - -**步骤3** 执行模型转换命令 - -``` -atc --model=rcf.prototxt --weight=./rcf_bsds.caffemodel --framework=0 --output=rcf --soc_version=Ascend310 --insert_op_conf=./aipp.cfg --input_format=NCHW --output_type=FP32 +└── CMakeLists.txt ``` -## 4 编译与运行 +## 2 设置环境变量 -**步骤1** 执行如下编译命令: -bash build.sh +```bash +#设置CANN环境变量 +. ${ascend-toolkit-path}/set_env.sh -**步骤2** 进行图像边缘检测 -请自行准备jpg格式的测试图像保存在文件夹中(例如 data/**.jpg)进行边缘检测 +#设置MindX SDK 环境变量,SDK-path为mxVision SDK 安装路径 +. ${SDK-path}/set_env.sh ``` -./edge_detection_picture ./data -``` -生成边缘检测图像 result/**.jpg - -## 5 精度测试 -下载开源数据集 BSDS500 [下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/EdgeDetectionPicture/data.zip), 使用 BSR/BSDS500/data/images/test数据进行测试 +## 3 准备模型 +**步骤1** 通过[下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/EdgeDetectionPicture/model.zip)下载RCF模型文件包。 -(1) 下载开源代码 +**步骤2** 将获取到的RCF模型文件内的`rcf.prototxt`文件和`rcf_bsds.caffemodel`文件放在`EdgeDetectionPicture/model/`下。 -``` shell -git clone https://github.com/Walstruzz/edge_eval_python.git -cd edge_eval_python +**步骤3** 在`EdgeDetectionPicture/model/`下执行模型转换命令: +```bash +atc --model=rcf.prototxt --weight=./rcf_bsds.caffemodel --framework=0 --output=rcf --soc_version=Ascend310P3 --insert_op_conf=./aipp.cfg --input_format=NCHW --output_type=FP32 ``` -(2) 编译cxx +执行完模型转换脚本后,若提示如下信息说明模型转换成功,可以在`EdgeDetectionPicture/model/`下找到名为`rcf.om`模型文件。 -``` shell -cd cxx/src -source build.sh ``` -(3) 将test中的图像经过边缘检测后的结果保存在result文件夹中 - -``` shell -./edge_detection_picture path/to/BSR/BSDS500/data/images/test/ - -``` - - -(4) 修改检测代码 +ATC run success, welcome to the next use. +``` -vim mian.py -注释第17行代码 nms_process(model_name_list, result_dir, save_dir, key, file_format), -修改18行为 eval_edge(alg, model_name_list, result_dir, gt_dir, workers) -vim /impl/edges_eval_dir.py -修改155行为 im = os.path.join(res_dir, "{}.jpg".format(i)) - -vim eval_edge.py -修改14行为 res_dir = result_dir - -(5) 测试精度 - -``` shell -python main.py --result_dir path/to/result --gt_dir paht/to/BSR/BSDS500/data/groundTruth/test +## 4 编译与运行 +**步骤1** 在`EdgeDetectionPicture/`下执行如下编译命令: +```bash +bash build.sh ``` -注: - result_dir: results directory - - gt_dir : ground truth directory +**步骤2** 进行图像边缘检测 -## 6常见问题 -### 6.1 精度测试脚本运行时, ModuleNotFoundError报错问题: -问题描述: -运行精度测试脚本过程中, 出现如下类似报错: -``` -********* -File "***/nms_process.py", line 6 in - from impl.toolbox import conv_tri, grad2 -ModuleNotFoundError: No module named 'impl.toolbox' -``` - -解决措施: +1. 在`EdgeDetectionPicture/`下创建文件夹`data`。 +2. 请自行准备jpg格式的测试图像,保存在`data/`文件夹内(例如 `data/**.jpg`) +3. 在`EdgeDetectionPicture/`下执行如下命令来进行边缘检测: +```bash +./edge_detection_picture ./data ``` -方法一: -将环境变量PYTHONPATH里面的/usr/local/Ascend/ascend-toolkit/latest/opp/built-in/op_impl/ai_core/tbe去掉, 该路径根据cann实际安装位置不同可能会不一样,须自行确认 +**步骤3** 查看结果 -方法二: -执行命令: unset PYTHONPATH -``` \ No newline at end of file +生成的边缘检测图像会以原测试图像名称保存在`EdgeDetectionPicture/result/`文件夹内。 (如`result/**.jpg`) diff --git a/contrib/EdgeDetectionPicture/rcfDetection/RcfDetection.cpp b/contrib/EdgeDetectionPicture/rcfDetection/RcfDetection.cpp index a8a84460c7a506e8b7cf4d34c0da439da1353074..435b3d2a5f88060803707ef3f2aa02218707bba7 100644 --- a/contrib/EdgeDetectionPicture/rcfDetection/RcfDetection.cpp +++ b/contrib/EdgeDetectionPicture/rcfDetection/RcfDetection.cpp @@ -39,7 +39,7 @@ void RcfDetection::SetRcfPostProcessConfig(const InitParam &initParam, configData.SetJsonValue("MODEL_TYPE", std::to_string(initParam.modelType)); configData.SetJsonValue("INPUT_TYPE", std::to_string(initParam.inputType)); configData.SetJsonValue("CHECK_MODEL", checkTensor); - auto jsonStr = configData.GetCfgJson().serialize(); + auto jsonStr = configData.GetCfgJson(); config["postProcessConfigContent"] = jsonStr; } @@ -57,11 +57,6 @@ APP_ERROR RcfDetection::Init(const InitParam &initParam) return ret; } dvppWrapper_ = std::make_shared(); - ret = dvppWrapper_->Init(); - if (ret != APP_ERR_OK) { - LogError << "DvppWrapper init failed, ret=" << ret << "."; - return ret; - } model_ = std::make_shared(); ret = model_->Init(initParam.modelPath, modelDesc_); if (ret != APP_ERR_OK) { @@ -86,7 +81,6 @@ APP_ERROR RcfDetection::Init(const InitParam &initParam) APP_ERROR RcfDetection::DeInit() { - dvppWrapper_->DeInit(); model_->DeInit(); post_->DeInit(); MxBase::DeviceManager::GetInstance()->DestroyDevices();