From f746c857b0723920146076a574002bf695f45ee5 Mon Sep 17 00:00:00 2001 From: anan505 <1204828624@qq.com> Date: Wed, 27 Nov 2024 11:58:32 +0000 Subject: [PATCH 1/7] update tutorials/ImageDetectionSample/C++/README.md. Signed-off-by: anan505 <1204828624@qq.com> --- tutorials/ImageDetectionSample/C++/README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tutorials/ImageDetectionSample/C++/README.md b/tutorials/ImageDetectionSample/C++/README.md index 78e4b0f04..94aa515fb 100644 --- a/tutorials/ImageDetectionSample/C++/README.md +++ b/tutorials/ImageDetectionSample/C++/README.md @@ -18,7 +18,7 @@ ### 1.4 三方依赖 无 -## 2. 设置环境变量 +## 2 设置环境变量 ```bash #设置CANN环境变量 @@ -28,7 +28,7 @@ . ${SDK-path}/set_env.sh ``` -## 3. 准备模型 +## 3 准备模型 **步骤1** 在ModelZoo上下载YOLOv3模型。[下载地址](https://gitee.com/link?target=https%3A%2F%2Fobs-9be7.obs.cn-east-2.myhuaweicloud.com%2F003_Atc_Models%2Fmodelzoo%2Fyolov3_tf.pb) @@ -60,7 +60,10 @@ ATC run success, welcome to the next use. 表示命令执行成功。 ## 4 编译与运行 -**步骤1:** 修改项目c++目录下的配置文件`./test.pipeline`: + +**步骤1:** 准备一张待检测图片,放到项目目录下命名为`test.jpg`。 + +**步骤2:** 修改项目c++目录下的配置文件`./test.pipeline`: 1. 在第32行 配置mxpi_tensorinfer插件的模型加载路径`modelPath`: ```bash @@ -93,7 +96,7 @@ ATC run success, welcome to the next use. 46 }, ``` -**步骤2:** 编译项目文件 +**步骤3:** 编译项目文件 在项目的c++目录下,新建立build目录,进入build执行cmake ..(..代表包含CMakeLists.txt的源文件父目录),在build目录下生成了编译需要的Makefile和中间文件。执行make构建工程,构建成功后就会生成可执行文件。 @@ -120,7 +123,7 @@ Scanning dependencies of target sample # sample就是CMakeLists文件中指定生成的可执行文件。 ``` -**步骤3:** 执行脚本 +**步骤4:** 执行脚本 执行run.sh脚本前请先确认可执行文件sample已生成。 @@ -132,7 +135,7 @@ chmod +x run.sh bash run.sh ``` -**步骤4:** 查看结果 +**步骤5:** 查看结果 执行run.sh完毕后,sample会将目标检测结果保存在工程目录下`result.jpg`中。 -- Gitee From 465edea4922785625cc2519d1497338b2d85f0df Mon Sep 17 00:00:00 2001 From: anan505 <1204828624@qq.com> Date: Wed, 27 Nov 2024 12:02:15 +0000 Subject: [PATCH 2/7] update tutorials/ImageDetectionSample/C++/README.md. Signed-off-by: anan505 <1204828624@qq.com> --- tutorials/ImageDetectionSample/C++/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tutorials/ImageDetectionSample/C++/README.md b/tutorials/ImageDetectionSample/C++/README.md index 94aa515fb..1eae49f59 100644 --- a/tutorials/ImageDetectionSample/C++/README.md +++ b/tutorials/ImageDetectionSample/C++/README.md @@ -80,7 +80,10 @@ ATC run success, welcome to the next use. 2. 在第41和42行 配置模型后处理插件mxpi_objectpostprocessor,添加`coco.names`与 `libyolov3postprocess.so`路径: -- 文件`coco.names`来源于下载的模型文件夹内。 +- 通过命令查找到文件`coco.names`路径: +```bash +find / -name coco.names +``` - `postProcessLibPath`的后处理库路径,路径根据SDK安装路径决定,可以通过`find / -name libyolov3postprocess.so`搜索路径。 ```bash @@ -88,7 +91,7 @@ ATC run success, welcome to the next use. 38 "props": { 39 "dataSource": "mxpi_tensorinfer0", 40 "postProcessConfigPath": "model/yolov3_tf_bs1_fp16.cfg", -41 "labelPath": "${YOLOv3模型文件夹路径}/coco.names", +41 "labelPath": "${coco.names文件路径}", 42 "postProcessLibPath": "${libyolov3postprocess.so路径}" 43 }, 44 "factory": "mxpi_objectpostprocessor", -- Gitee From 212bcacd8676fcab03c0eb6985ac386e9e4067ef Mon Sep 17 00:00:00 2001 From: anan505 <1204828624@qq.com> Date: Wed, 27 Nov 2024 12:03:33 +0000 Subject: [PATCH 3/7] update tutorials/ImageDetectionSample/C++/main.cpp. Signed-off-by: anan505 <1204828624@qq.com> --- tutorials/ImageDetectionSample/C++/main.cpp | 90 ++++++++++----------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/tutorials/ImageDetectionSample/C++/main.cpp b/tutorials/ImageDetectionSample/C++/main.cpp index 118de9b4d..fc1f55a2e 100644 --- a/tutorials/ImageDetectionSample/C++/main.cpp +++ b/tutorials/ImageDetectionSample/C++/main.cpp @@ -175,62 +175,62 @@ static APP_ERROR PrintInfo(std::vector outPutInfo) return APP_ERR_OK; } -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { // 读取test.pipeline文件信息 std::string pipelineConfigPath = "./test.pipeline"; std::string pipelineConfig = ReadPipelineConfig(pipelineConfigPath); - if(pipelineConfig == ""){ + if (pipelineConfig == "") { return APP_ERR_COMM_INIT_FAIL; } std::string streamName = "detection"; // 新建一个流管理MxStreamManager对象并初始化 - auto mxStreamManager = std::make_shared(); - APP_ERROR ret = mxStreamManager->InitManager(); - if(ret != APP_ERR_OK){ - LogError << GetError(ret) << "Fail to init Stream manager."; - return ret; - } - // 加载pipeline得到的信息,创建一个新的stream业务流 - ret = mxStreamManager->CreateMultipleStreams(pipelineConfig); - if(ret != APP_ERR_OK){ - LogError << GetError(ret) << "Fail to creat Stream."; - return ret; - } + { + auto mxStreamManager = std::make_shared(); + APP_ERROR ret = mxStreamManager->InitManager(); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Fail to init Stream manager."; + return ret; + } + // 加载pipeline得到的信息,创建一个新的stream业务流 + ret = mxStreamManager->CreateMultipleStreams(pipelineConfig); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Fail to creat Stream."; + return ret; + } - // 将图片的信息读取到dataBuffer中 - MxStream::MxstDataInput dataBuffer; - ret = ReadFile("./test.jpg", dataBuffer); - if(ret != APP_ERR_OK){ - LogError << "Fail to read image file, ret = " << ret << "."; - return ret; - } - // 通过SendData函数传递输入信息到指定的工作元件模块 - // streamName是pipeline文件中业务流名称;inPluginId为输入端口编号,对应输入元件的编号 - ret = mxStreamManager->SendData(streamName, 0, dataBuffer); - if(ret != APP_ERR_OK){ + // 将图片的信息读取到dataBuffer中 + MxStream::MxstDataInput dataBuffer; + ret = ReadFile("./test.jpg", dataBuffer); + if (ret != APP_ERR_OK) { + LogError << "Fail to read image file, ret = " << ret << "."; + return ret; + } + // 通过SendData函数传递输入信息到指定的工作元件模块 + // streamName是pipeline文件中业务流名称;inPluginId为输入端口编号,对应输入元件的编号 + ret = mxStreamManager->SendData(streamName, 0, dataBuffer); + if (ret != APP_ERR_OK) { + delete dataBuffer.dataPtr; + LogError << "Fail to send data to stream, ret = " << ret << "."; + return ret; + } delete dataBuffer.dataPtr; - LogError << "Fail to send data to stream, ret = " << ret << "."; - return ret; - } - delete dataBuffer.dataPtr; - // 获得Stream上输出原件的protobuf结果 - std::vector keyVec = {"mxpi_objectpostprocessor0", "mxpi_imagedecoder0"}; - std::vector output = mxStreamManager->GetProtobuf(streamName, 0, keyVec); - ret = PrintInfo(output); - if(ret != APP_ERR_OK){ - LogError << "Fail to print the info of output, ret = " << ret << "."; - return ret; - } + // 获得Stream上输出原件的protobuf结果 + std::vector keyVec = {"mxpi_objectpostprocessor0", "mxpi_imagedecoder0"}; + std::vector output = mxStreamManager->GetProtobuf(streamName, 0, keyVec); + ret = PrintInfo(output); + if (ret != APP_ERR_OK) { + LogError << "Fail to print the info of output, ret = " << ret << "."; + return ret; + } - // mxpi_objectpostprocessor0模型后处理插件输出信息 - auto objectList = std::static_pointer_cast(output[0].messagePtr); - // mxpi_imagedecoder0图片解码插件输出信息 - auto mxpiVision = std::static_pointer_cast(output[1].messagePtr); - // 将结果写入本地图片中 - SaveResult(mxpiVision, objectList); - mxStreamManager->DestroyAllStreams(); + // mxpi_objectpostprocessor0模型后处理插件输出信息 + auto objectList = std::static_pointer_cast(output[0].messagePtr); + // mxpi_imagedecoder0图片解码插件输出信息 + auto mxpiVision = std::static_pointer_cast(output[1].messagePtr); + // 将结果写入本地图片中 + SaveResult(mxpiVision, objectList); + } return 0; } -- Gitee From 2e821853372fa08a82ddfc0a3dadad888df4d34f Mon Sep 17 00:00:00 2001 From: anan505 <1204828624@qq.com> Date: Wed, 27 Nov 2024 12:04:13 +0000 Subject: [PATCH 4/7] update tutorials/ImageDetectionSample/python/models/model_conversion.sh. Signed-off-by: anan505 <1204828624@qq.com> --- .../ImageDetectionSample/python/models/model_conversion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/ImageDetectionSample/python/models/model_conversion.sh b/tutorials/ImageDetectionSample/python/models/model_conversion.sh index deb96e420..b4875ca3c 100644 --- a/tutorials/ImageDetectionSample/python/models/model_conversion.sh +++ b/tutorials/ImageDetectionSample/python/models/model_conversion.sh @@ -32,5 +32,5 @@ export ASCEND_OPP_PATH=${install_path}/opp # 执行,转换YOLOv3模型 # Execute, transform YOLOv3 model. -atc --model=./yolov3_tf.pb --framework=3 --output=./yolov3_tf_bs1_fp16 --soc_version=Ascend310 --insert_op_conf=./aipp_yolov3_416_416.aippconfig --input_shape="input:1,416,416,3" --out_nodes="yolov3/yolov3_head/Conv_6/BiasAdd:0;yolov3/yolov3_head/Conv_14/BiasAdd:0;yolov3/yolov3_head/Conv_22/BiasAdd:0" +atc --model=./yolov3_tf.pb --framework=3 --output=./yolov3_tf_bs1_fp16 --soc_version=Ascend310P3 --insert_op_conf=./aipp_yolov3_416_416.aippconfig --input_shape="input:1,416,416,3" --out_nodes="yolov3/yolov3_head/Conv_6/BiasAdd:0;yolov3/yolov3_head/Conv_14/BiasAdd:0;yolov3/yolov3_head/Conv_22/BiasAdd:0" # 说明:out_nodes制定了输出节点的顺序,需要与模型后处理适配。 \ No newline at end of file -- Gitee From 4c467b4b3db9ef8948e8ff98714c1f4bfa5fc580 Mon Sep 17 00:00:00 2001 From: anan505 <1204828624@qq.com> Date: Wed, 27 Nov 2024 12:05:03 +0000 Subject: [PATCH 5/7] update tutorials/ImageDetectionSample/python/README.md. Signed-off-by: anan505 <1204828624@qq.com> --- tutorials/ImageDetectionSample/python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/ImageDetectionSample/python/README.md b/tutorials/ImageDetectionSample/python/README.md index cb53e5c72..5896e95a2 100644 --- a/tutorials/ImageDetectionSample/python/README.md +++ b/tutorials/ImageDetectionSample/python/README.md @@ -23,7 +23,7 @@ | 软件名称 | 版本 | |------------------------|-----------| | numpy | 1.22.4 | -| opencv-python-headless | 4.10.0.84 | +| opencv-python | 4.10.0.84 | ## 2. 设置环境变量 -- Gitee From 72ed6cb5cf9e4ac55c14d85c06fc90fba7f30d72 Mon Sep 17 00:00:00 2001 From: anan505 <1204828624@qq.com> Date: Wed, 27 Nov 2024 12:23:35 +0000 Subject: [PATCH 6/7] update tutorials/ImageDetectionSample/C++/README.md. Signed-off-by: anan505 <1204828624@qq.com> --- tutorials/ImageDetectionSample/C++/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/ImageDetectionSample/C++/README.md b/tutorials/ImageDetectionSample/C++/README.md index 1eae49f59..067197893 100644 --- a/tutorials/ImageDetectionSample/C++/README.md +++ b/tutorials/ImageDetectionSample/C++/README.md @@ -52,7 +52,7 @@ mv ./C++ ./C atc --model=./yolov3_tf.pb --framework=3 --output=./yolov3_tf_bs1_fp16 --soc_version=Ascend310P3 --insert_op_conf=./aipp_yolov3_416_416.aippconfig --input_shape="input:1,416,416,3" --out_nodes="yolov3/yolov3_head/Conv_6/BiasAdd:0;yolov3/yolov3_head/Conv_14/BiasAdd:0;yolov3/yolov3_head/Conv_22/BiasAdd:0" # 说明:out_nodes制定了输出节点的顺序,需要与模型后处理适配。 ``` -执行完模型转换脚本后,在`model/`目录下会生成相应的`.om`模型文件。执行后终端输出为: +执行完模型转换脚本后,在`model/`目录下会生成相应的`yolov3_tf_bs1_fp16.om`模型文件。执行后终端输出为: ```bash ATC start working now, please wait for a moment. ATC run success, welcome to the next use. @@ -70,7 +70,7 @@ ATC run success, welcome to the next use. 29 "mxpi_tensorinfer0": { 30 "props": { 31 "dataSource": "mxpi_imageresize0", -32 "modelPath": "${yolov3.om模型路径}" +32 "modelPath": "${yolov3_tf_bs1_fp16.om模型路径}" 33 }, 34 "factory": "mxpi_tensorinfer", 35 "next": "mxpi_objectpostprocessor0" -- Gitee From b75b804d198889bb27d83adb2a072d1349c8b0dd Mon Sep 17 00:00:00 2001 From: anan505 <1204828624@qq.com> Date: Wed, 27 Nov 2024 12:24:17 +0000 Subject: [PATCH 7/7] update tutorials/ImageDetectionSample/C++/README.md. Signed-off-by: anan505 <1204828624@qq.com> --- tutorials/ImageDetectionSample/C++/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/ImageDetectionSample/C++/README.md b/tutorials/ImageDetectionSample/C++/README.md index 067197893..9dc33ae1d 100644 --- a/tutorials/ImageDetectionSample/C++/README.md +++ b/tutorials/ImageDetectionSample/C++/README.md @@ -43,7 +43,7 @@ mv ./C++ ./C ``` -在`model/`目录下执行以下命令 +在`C/model/`目录下执行以下命令 ```bash # 执行,转换YOLOv3模型 -- Gitee