App Running

The sample procedure applies to the following products:

  • Atlas 200/300/500 Inference Product
  • Atlas Training Series Product

Model Conversion

  1. Log in to the development environment as the HwHiAiUser user (running user).
  2. Obtain the ATC tool and set environment variables by referring to ATC Instructions.
  3. Prepare data.

    Obtain the ResNet-50 weight file (.caffemodel) and model file (resnet50.prototxt) from the following link and upload the files to the caffe_model directory under the vpc_jpeg_resnet50_imagenet_classification directory sample in the development environment as the HwHiAiUser user (running user).

    • Visit our ModelZoo repository on Gitee and find the download links in the README.md file.
    • Visit our ModelZoo repository on GitHub and find the download links in the README.md file.
  4. Convert the ResNet-50 network into an offline model (.om file) adapted to the Ascend AI Processor. During model conversion, you need to set CSC parameters to convert YUV420SP images to RGB images.

    Go to the vpc_jpeg_resnet50_imagenet_classification directory and run the following command. Ascendxxx indicates the Ascend AI Processor version. Replace it with the actual one.

    atc --model=caffe_model/resnet50.prototxt --weight=caffe_model/resnet50.caffemodel --framework=0 --output=model/resnet50_aipp --soc_version=Ascendxxx --insert_op_conf=caffe_model/aipp.cfg
    • --output: The generated resnet50_aipp.om file is stored in the vpc_jpeg_resnet50_imagenet_classification/model directory.
    • Before running the atc command, ensure that you have the write permission on the vpc_jpeg_resnet50_imagenet_classification directory.
    • If the soc_version of the current device cannot be determined, run the npu-smi info command on the server where the NPU driver package is installed and add Ascend information before the queried Name. For example, if the value of Name is xxxyy, the actual soc_version is Ascend xxxyy.
  5. As the HwHiAiUser running user, upload the sample directory in the development environment to the operating environment.

App Running

  1. Log in to the operating environment.
  2. Prepare an input image. Click the following links to download the input images of this sample and upload the images to the vpc_jpeg_resnet50_imagenet_classification/data directory in the development environment as the running user. If the directory does not exist, create it.
  3. Configure the operating environment by referring to Environment Variable Configuration.
  4. Run the corresponding command as required under vpc_jpeg_resnet50_imagenet_classification.
    • Perform decoding, resizing, and inference.
      python3 ./src/main.py --images_path="./data/wood_rabbit_1024_1061_330.jpg" --dvpp_type=0 --image_type='jpg'
    • Perform cropping.
      python3 ./src/main.py --images_path="./data/wood_rabbit_1024_1068_nv12.yuv" --dvpp_type=1 --image_type='yuv'
    • Paste the cropped image.
      python3 ./src/main.py --images_path="./data/wood_rabbit_1024_1068_nv12.yuv" --dvpp_type=2 --image_type='yuv'
    • Perform encoding.
      python3 ./src/main.py --images_path="./data/wood_rabbit_1024_1068_nv12.yuv" --dvpp_type=3 --image_type='yuv'
    • Perform 8K resizing.
      Change the name of the dvpp_vpc_8192x8192_nv12.yuv file in the data directory to dvpp_vpc_8192_8192_nv12.yuv.
      python3 ./src/main.py --images_path="./data/dvpp_vpc_8192_8192_nv12.yuv" --dvpp_type=4 --image_type='yuv'
    • Perform batch image cropping.
      python3 ./src/main.py --images_path="./data/wood_rabbit_1024_1068_nv12.yuv" --dvpp_type=5 --image_type='yuv' --in_batch_size=1 --out_batch_size=8
    • Paste the cropped image.
      python3 ./src/main.py --images_path="./data/wood_rabbit_1024_1068_nv12.yuv" --dvpp_type=6 --image_type='yuv' --in_batch_size=1 --out_batch_size=8
  5. Check the execution result. You should find the following information upon execution success:
    Using device id:0
    model path:./model/resnet50_aipp.om
    images path:./data/wood_rabbit_1024_1068_nv12.yuv
    result path:./vpc_out
    dvpp type:6
    
    [Sample] init resource stage:
    [Sample] init resource stage success
    [Model] class Model init resource stage:
    [Model] create model output dataset:
    [Model] create model output dataset success
    [Model] class Model init resource stage success
    [Dvpp] class Dvpp init resource stage:
    [Dvpp] class Dvpp init resource stage:
    [Sample] image:./data/wood_rabbit_1024_1068_nv12.yuv res_path:./vpc_out
    [Sample] width:1024 height:1068
    [Sample] in_batch_size:1 in_batch_size:8
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_0_.yuv success
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_1_.yuv success
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_2_.yuv success
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_3_.yuv success
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_4_.yuv success
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_5_.yuv success
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_6_.yuv success
    [Sample]write out to file ./vpc_out/wood_rabbit_1024_1068_nv12_6crop_7_.yuv success
    [Model] class Model release source success
    [Dvpp] class Dvpp release source
    [Dvpp] class Dvpp release source success
    [Sample] class Sample release source success