English|中文
This sample provides reference for you to learn the Ascend AI Software Stack and cannot be used for commercial purposes.
This sample applies to CANN 3.0.0 and later versions, and supports Atlas 200 DK and Atlas 300 (AI1s).
This readme file provides only guidance for running the sample in command line (CLI) mode. For details about how to run the sample in MindStudio, see Running Image Samples in MindStudio.
Function: cartoonizes an input image by using the CartoonGAN model.
Input: JPG image
Output: JPG image with inference results
Before deploying this sample, ensure that:
-
The environment has been set up by referring to Environment Preparation and Dependency Installation.
-
The development environment and operating environment of the corresponding product have been installed.
-
Obtain the source code package.
You can download the source code in either of the following ways:
-
Command line (The download takes a long time, but the procedure is simple.)
In the development environment, run the following commands as a non-root user to download the source code repository:
cd $HOME
git clone https://github.com/Ascend/samples.git
-
Compressed package (The download takes a short time, but the procedure is complex.)
-
Click Clone or download in the upper right corner of the samples repository and click Download ZIP.
-
Upload the .zip package to the home directory of a common user in the development environment, for example, $HOME/ascend-samples-master.zip.
-
In the development environment, run the following commands to unzip the package:
cd $HOME
unzip ascend-samples-master.zip
-
-
-
Obtain the source model required by the application。
-
For CANN 3.1.0
Due to versioning issues, this model was not converted correctly in version 3.1.0.So version 3.1.0 gets the OM model directly.cd $HOME/samples/cplusplus/contrib/cartoonGAN_picture/model
wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/cartoonGAN_picture/cplus/cartoonization.om -
For CANN 3.0.0
-
Refer to the link below for the original network model used in this application。
cd $HOME/samples/cplusplus/contrib/cartoonGAN_picture/model 。
wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/cartoon/cartoonization.pb -
Set the LD_LIBRARY_PATH environment variable. The LD_LIBRARY_PATH environment variable conflicts with the sample when the ATC tool is used. Therefore, you need to set this environment variable separately in the CLI to facilitate modification.
export install_path=$HOME/Ascend/ascend-toolkit/latest
export LD_LIBRARY_PATH=\${install_path}/atc/lib64
-
Run the following commands to convert the model:
atc --output_type=FP32 --input_shape="train_real_A:1,256,256,3" --input_format=NHWC --output="./cartoonization" --soc_version=Ascend310 --framework=3 --save_original_model=false --model="./cartoonization.pb" --precision_mode=allow_fp32_to_fp16
-
-
-
Obtain the test image required by the sample.
Run the following commands to go to the data folder of the sample and download the corresponding test image:
cd $HOME/samples/python/contrib/cartoonGAN_picture/data
wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/cartoonGAN_picture/scenery.jpg
Note: If the development environment and operating environment are set up on the same server, skip step 1 and go to step 2 directly.
-
Run the following commands to upload the cartoonGAN_picture directory in the development environment to any directory in the operating environment, for example, /home/HwHiAiUser, and log in to the operating environment (host) as the HwHiAiUser user:
scp -r $HOME/samples/python/contrib/cartoonGAN_picture/ HwHiAiUser@xxx.xxx.xxx.xxx:/home/HwHiAiUser
ssh HwHiAiUser@xxx.xxx.xxx.xxx
- In the following information, xxx.xxx.xxx.xxx is the IP address of the operating environment. The IP address of Atlas 200 DK is 192.168.1.2 when it is connected over the USB port, and that of Atlas 300 (AI1s) is the corresponding public IP address.
-
Run the executable file.
-
If the development environment and operating environment are set up on the same server, run the following commands to set the operating environment variables and switch the directory:
export LD_LIBRARY_PATH=
source ~/.bashrc
cd $HOME/samples/python/contrib/cartoonGAN_picture/src
python3.6 cartoonization.py ../data/ -
If the development environment and operating environment are set up on separate servers, run the following command to switch the directory:
cd $HOME/YOLOV3_coco_detection_picture/src
Run the following command to run the sample:
python3.6 cartoonization.py ../data/
-
After the execution is complete, find the JPG image with inference results in the outputs directory.
