From be0e6f62e0f7efa89d905553a18d330462dfea32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:14:34 +0000 Subject: [PATCH 1/9] update contrib/Colorization/src/main.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/src/main.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/contrib/Colorization/src/main.py b/contrib/Colorization/src/main.py index 6d4b07778..7ddcbed32 100644 --- a/contrib/Colorization/src/main.py +++ b/contrib/Colorization/src/main.py @@ -34,7 +34,7 @@ CHANL_NUM = 2 IMG_CHW_NUM = 3 IMG_CHW_MAX = 255 L_CHANL_DATA = 50 -OUTPUT_DIR = '../out/' +OUTPUT_DIR = './' def preprocess(picPath): # 抽取黑白图像L通道 @@ -68,21 +68,16 @@ def postprocess(result_list, pic, orig_shape, orig_l): result_list = result_list.reshape(1, CHANL_NUM, OUT_W, OUT_H).transpose(0, CHANL_NUM, IMG_CHW_NUM, 1) result_array = result_list[0] - + print(result_array) ab_data = cv.resize(result_array, orig_shape[::-1]) result_lab = np.concatenate((orig_l[:, :, np.newaxis], ab_data), axis=2) result_bgr = (IMG_CHW_MAX * np.clip(cv.cvtColor(result_lab, cv.COLOR_Lab2BGR), 0, 1)).astype('uint8') - file_name = os.path.join(OUTPUT_DIR, "out_" + os.path.basename(pic)) cv.imwrite(file_name, result_bgr) if __name__ == '__main__': - if len(sys.argv) <= 1: - print("Please enter external parameters.") - exit() - else: - inputPic = sys.argv[1] + inputPic = "../data/dog.png" # 新建一个流管理StreamManager对象并初始化 streamManagerApi = StreamManagerApi() -- Gitee From 388370519dbeadc95791b4f718d4c73b765ca750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:15:29 +0000 Subject: [PATCH 2/9] update contrib/Colorization/scripts/atc_run.sh. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/scripts/atc_run.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/contrib/Colorization/scripts/atc_run.sh b/contrib/Colorization/scripts/atc_run.sh index 1e7ef3a5b..a7f83a8aa 100644 --- a/contrib/Colorization/scripts/atc_run.sh +++ b/contrib/Colorization/scripts/atc_run.sh @@ -13,11 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -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:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp - cd ../model -atc --input_shape="data_l:1,1,224,224" --weight="./colorization.caffemodel" --input_format=NCHW --output="colorization" --soc_version=Ascend310 --framework=0 --model="./colorization.prototxt" +atc --input_shape="data_l:1,1,224,224" --weight="./colorization.caffemodel" --input_format=NCHW --output="colorization" --soc_version=Ascend310P3 --framework=0 --model="./colorization.prototxt" -- Gitee From ced50813a04df25cce2ce46f3130cb0f2c6957b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:16:11 +0000 Subject: [PATCH 3/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20cont?= =?UTF-8?q?rib/Colorization/scripts/run.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/Colorization/scripts/run.sh | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 contrib/Colorization/scripts/run.sh diff --git a/contrib/Colorization/scripts/run.sh b/contrib/Colorization/scripts/run.sh deleted file mode 100644 index 8abca1228..000000000 --- a/contrib/Colorization/scripts/run.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -# 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. - -set -e - -INPUT_PIC="../data/dog.png" - -export MX_SDK_HOME="${YOUR_PATH}/MindX_SDK/mxVision" -export LD_LIBRARY_PATH=${MX_SDK_HOME}/lib:${MX_SDK_HOME}/opensource/lib:${MX_SDK_HOME}/opensource/lib64:/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:${LD_LIBRARY_PATH} -export GST_PLUGIN_SCANNER=${MX_SDK_HOME}/opensource/libexec/gstreamer-1.0/gst-plugin-scanner -export GST_PLUGIN_PATH=${MX_SDK_HOME}/opensource/lib/gstreamer-1.0:${MX_SDK_HOME}/lib/plugins - -#to set PYTHONPATH, import the StreamManagerApi.py -export PYTHONPATH=$PYTHONPATH:${MX_SDK_HOME}/python - -python3 ../src/main.py $INPUT_PIC -exit 0 -- Gitee From 2eed19630935ba640e4d02dd58f3dc85a8971b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:26:39 +0000 Subject: [PATCH 4/9] update contrib/Colorization/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/README.md | 86 +++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/contrib/Colorization/README.md b/contrib/Colorization/README.md index 7578f1a89..c760940b9 100644 --- a/contrib/Colorization/README.md +++ b/contrib/Colorization/README.md @@ -2,6 +2,8 @@ ## 1 介绍 +### 1.1 简介 + 在智能手机越来越普及的今天,拍摄一张色彩鲜艳、清晰的照片轻而易举。但是老照片没有如此“幸运”,大多为黑白。借助人工智能,可以一定程度上帮助老照片还原原来色彩。 本项目是黑白图像上色应用,旨在华为Atlas300推理芯片上实现输入黑白图像,自动对黑白图像进行上色,还原彩色图像。 @@ -10,80 +12,98 @@ Atlas300推理芯片 -### 1.2 代码目录结构与说明 +### 1.2 支持的产品 + +本项目支持昇腾Atlas 300I pro、 Atlas 300V pro + +### 1.3 支持的版本 +本样例配套的MxVision版本、CANN版本、Driver/Firmware版本如下所示: + +| MxVision版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | +### 1.4 三方依赖 + +第三方依赖软件和版本如下表。请确认环境已安装pip3后,使用pip3 install 安装以下依赖。 +|软件名称 | 版本 | +|-----------|-----------| +| numpy | 1.24.0 | +| opencv-python | 4.9.0.80 | +### 1.5 代码目录结构说明 ``` . ├── data //需要手动创建 ├── model //需要手动创建 │   ├── colorization.caffemodel │   └── colorization.prototxt -├── out //需要手动创建 ├── pipeline │   └── colorization.pipeline ├── README.md ├── scripts │   ├── atc_run.sh -│   └── run.sh └── src └── main.py ``` -## 2 环境依赖 - -### 2.1 环境变量 - -模型转换和工程运行的环境变量已写入对应的shell脚本中 +## 2 设置环境变量 -### 2.2 软件依赖 +```bash +#设置CANN环境变量,ascend-toolkit-path为cann安装路径 +. ${ascend-toolkit-path}/set_env.sh -| 依赖软件 | 版本 | -|------------------|-------| -| CANN | 20.2.rc1| -| python | 3.9.2 | -| MindX_SDK | 2.0.4 | -| opencv-python | 4.5.3 | -| numpy | 1.21.2| +#设置MindX SDK 环境变量,SDK-path为mxVision SDK 安装路径 +. ${SDK-path}/set_env.sh +``` -## 3 运行 +## 3 准备模型 -示例步骤如下: -### 3.1 模型转换 +**步骤1:** 获取face_mask_detection的原始模型 -本工程原模型是caffee模型,需要使用atc工具转换为om模型,模型和所需权重文件已上传,请使用以下命令下载并解压 +本工程原模型是caffee模型,需要使用atc工具转换为om模型,模型和所需权重文件已上传,在项目根目录下使用以下命令下载并解压 ``` +mkdir model cd model wget https://mindx.sdk.obs.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/Colorization/model.zip unzip model.zip ``` -下载并解压完毕后,进入scripts目录执行模型转换脚本 +**步骤2:**模型转换 +下载并解压完毕后,在项目根目录下进入scripts目录执行模型转换脚本 ``` -cd ../scripts +cd scripts bash atc_run.sh ``` +执行完模型转换后,若提示如下信息说明模型转换成功。 + +``` +ATC run success, welcome to the next use. +``` +## 4 运行 -### 3.2 获取测试图片 +**步骤1:** 获取测试图片 -将待上色图片移动至data目录。本样例使用图片方式获取如下 +在项目根目录下执行: ``` -cd ../data +mkdir data +cd data wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/colorization_picture-python/dog.png ``` -### 3.3 运行推理工程 - -进入scripts目录,修改run.sh文件中INPUT_PIC变量为输入图片的路径,本示例为"../data/dog.png",修改MX_SDK_HOME环境变量为SDK实际安装路径。 -执行脚本 +**步骤2:** 修改pipeline文件 +根据使用的设备id,修改项目根目录下pipeline/colorization.pipeline中第四行的deviceId: +``` +"deviceId": "0" # 根据实际使用的设备id修改 +**步骤3:** 执行程序 ``` -cd ../scripts -bash run.sh +cd src +python3 main.cpp ``` - -输出结果保存在out目录下,下载至本地查看图片上色是否合理 +**步骤4:** 查看结果 +输出结果保存在src/out_dog.png,下载至本地查看图片上色是否合理 -- Gitee From dc61169b26d9c653292e02075cbf258283664a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:29:06 +0000 Subject: [PATCH 5/9] update contrib/Colorization/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/contrib/Colorization/README.md b/contrib/Colorization/README.md index c760940b9..01c5cc7c4 100644 --- a/contrib/Colorization/README.md +++ b/contrib/Colorization/README.md @@ -8,10 +8,6 @@ 本项目是黑白图像上色应用,旨在华为Atlas300推理芯片上实现输入黑白图像,自动对黑白图像进行上色,还原彩色图像。 -### 1.1 支持的产品 - -Atlas300推理芯片 - ### 1.2 支持的产品 本项目支持昇腾Atlas 300I pro、 Atlas 300V pro @@ -69,7 +65,7 @@ wget https://mindx.sdk.obs.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/C unzip model.zip ``` -**步骤2:**模型转换 +**步骤2:** 模型转换 下载并解压完毕后,在项目根目录下进入scripts目录执行模型转换脚本 ``` @@ -97,8 +93,8 @@ wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/colorization_pictur 根据使用的设备id,修改项目根目录下pipeline/colorization.pipeline中第四行的deviceId: ``` "deviceId": "0" # 根据实际使用的设备id修改 +``` **步骤3:** 执行程序 - ``` cd src python3 main.cpp -- Gitee From e741c730d09a5e701975596a05e8190cbd48ae44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:31:00 +0000 Subject: [PATCH 6/9] update contrib/Colorization/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/Colorization/README.md b/contrib/Colorization/README.md index 01c5cc7c4..e825b59d6 100644 --- a/contrib/Colorization/README.md +++ b/contrib/Colorization/README.md @@ -66,6 +66,7 @@ unzip model.zip ``` **步骤2:** 模型转换 + 下载并解压完毕后,在项目根目录下进入scripts目录执行模型转换脚本 ``` @@ -100,6 +101,7 @@ cd src python3 main.cpp ``` **步骤4:** 查看结果 + 输出结果保存在src/out_dog.png,下载至本地查看图片上色是否合理 -- Gitee From d5e3ecfc06bf1fafa983f6fea665ff1e64b7164a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:31:31 +0000 Subject: [PATCH 7/9] update contrib/Colorization/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/Colorization/README.md b/contrib/Colorization/README.md index e825b59d6..db24a0967 100644 --- a/contrib/Colorization/README.md +++ b/contrib/Colorization/README.md @@ -91,6 +91,7 @@ wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/colorization_pictur ``` **步骤2:** 修改pipeline文件 + 根据使用的设备id,修改项目根目录下pipeline/colorization.pipeline中第四行的deviceId: ``` "deviceId": "0" # 根据实际使用的设备id修改 -- Gitee From af4979b3f12cf416f31cdb88ff90a13d690de36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:34:53 +0000 Subject: [PATCH 8/9] update contrib/Colorization/src/main.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/src/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/Colorization/src/main.py b/contrib/Colorization/src/main.py index 7ddcbed32..c9d184cf6 100644 --- a/contrib/Colorization/src/main.py +++ b/contrib/Colorization/src/main.py @@ -68,7 +68,6 @@ def postprocess(result_list, pic, orig_shape, orig_l): result_list = result_list.reshape(1, CHANL_NUM, OUT_W, OUT_H).transpose(0, CHANL_NUM, IMG_CHW_NUM, 1) result_array = result_list[0] - print(result_array) ab_data = cv.resize(result_array, orig_shape[::-1]) result_lab = np.concatenate((orig_l[:, :, np.newaxis], ab_data), axis=2) result_bgr = (IMG_CHW_MAX * np.clip(cv.cvtColor(result_lab, cv.COLOR_Lab2BGR), 0, 1)).astype('uint8') -- Gitee From 84c30e4092e6f36861bc790f4091e45edd3e9db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A2=E4=B9=90=E9=A9=AC?= Date: Tue, 17 Dec 2024 03:35:15 +0000 Subject: [PATCH 9/9] update contrib/Colorization/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 欢乐马 --- contrib/Colorization/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/Colorization/README.md b/contrib/Colorization/README.md index db24a0967..eb6fbda07 100644 --- a/contrib/Colorization/README.md +++ b/contrib/Colorization/README.md @@ -99,7 +99,7 @@ wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/colorization_pictur **步骤3:** 执行程序 ``` cd src -python3 main.cpp +python3 main.py ``` **步骤4:** 查看结果 -- Gitee