更新时间:2021-10-26 GMT+08:00
分享

Ascend RC,编译及运行应用

  1. 模型转换。

    1. 以HwHiAiUser(运行用户)登录开发环境
    2. 参考ATC工具使用指导中的使用ATC工具转换模型,执行“准备动作”,包括获取工具、设置环境变量。
    3. 准备数据。

      从以下链接获取ResNet-50网络的权重文件(*.caffemodel),并以HwHiAiUser(运行用户)将获取的文件上传至开发环境“acl_vdec_resnet50/caffe_model”目录下。

      • 从gitee上获取:单击Link,查看README.md,查找获取原始模型的链接。
      • 从GitHub上获取:单击Link,查看README.md,查找获取原始模型的链接。
    4. 将ResNet-50网络转换为适配昇腾AI处理器的离线模型(*.om文件),转换模型时,需配置色域转换参数,用于将YUV420SP格式的图片转换为RGB格式的图片。

      切换到“acl_vdec_resnet50”目录,执行如下命令:

      atc --model=caffe_model/resnet50.prototxt --weight=caffe_model/resnet50.caffemodel --framework=0 --output=model/resnet50_aipp --soc_version=Ascend310 --insert_op_conf=caffe_model/aipp.cfg
      --output参数:生成的resnet50_aipp.om文件存放在“acl_vdec_resnet50/model”目录下。建议使用命令中的默认设置,否则在编译代码前,您还需要修改sample_process.cpp中的omModelPath参数值。
      const char* omModelPath = "../model/resnet50_aipp.om";

      关于各参数的详细解释,请参见ATC工具使用指导中的“约束及参数说明”

  2. 编译代码。

    1. 准备输入视频码流。

      https://gitee.com/HuaweiAscend/tools/tree/master/dvpp_sample_input_data上获取输入视频码流文件vdec_h265_1frame_rabbit_1280x720.h265,并以HwHiAiUser(运行用户)上传至开发环境“acl_vdec_resnet50”目录下。

    2. 以HwHiAiUser(运行用户)登录开发环境
    3. 设置环境变量,编译脚本src/CMakeLists.txt通过环境变量所设置的头文件、库文件的路径来编译代码。

      编译脚本CMakeLists.txt中已默认设置编译依赖的头文件路径(/usr/local/Ascend/ascend-toolkit/latest/acllib/include/)、库文件路径(/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub/)。

      如果未设置${DDK_PATH}、${NPU_HOST_LIB}环境变量,则以编译脚本CMakeLists.txt中的路径为准;如果已设置${DDK_PATH}、${NPU_HOST_LIB}环境变量,则编译脚本CMakeLists.txt优先以环境变量为准,按环境变量指向的路径查找编译依赖的头文件和库文件。

      如下为设置环境变量的示例,请将/home/HwHiAiUser/Ascend/ascend-toolkit/latest替换为Ascend RC形态的ACLlib安装包的实际安装路径。
      export DDK_PATH=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/arm64-linux
      export NPU_HOST_LIB=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/arm64-linux/acllib/lib64/stub

      使用“/home/HwHiAiUser/Ascend/ascend-toolkit/latest/arm64-linux/acllib/lib64/stub”目录下的*.so库,是为了编译基于ACL接口的代码逻辑时,不依赖其它组件(例如Driver)的任何*.so库。

      编译通过后,在开发者板上运行应用时,通过配置环境变量,应用会链接到开发者板上“/home/HwHiAiUser/Ascend/acllib/lib64”目录下的*.so库,运行时会自动链接到依赖其它组件的*.so库。

    4. 切换到“acl_vdec_resnet50”目录,创建目录用于存放编译文件,例如,本文中,创建的目录为“build/intermediates/minirc”
      mkdir -p build/intermediates/minirc
    5. 切换到“build/intermediates/minirc”目录,执行cmake生成编译文件。
      “../../../src”表示CMakeLists.txt文件所在的目录,请根据实际目录层级修改。
      cd build/intermediates/minirc
      cmake ../../../src -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_SKIP_RPATH=TRUE
    6. 执行make命令,生成的可执行文件main在“acl_vdec_resnet50/out”目录下。
      make

  3. 运行应用。

    1. 以HwHiAiUser(运行用户)将开发环境“acl_vdec_resnet50”目录下的src目录、out目录、data目录、model目录上传到开发者板的同一个目录下,例如“/home/HwHiAiUser/acl_vdec_resnet50”
    2. 以HwHiAiUser(运行用户)登录开发者板
    3. 设置环境变量。
      如下为设置环境变量的示例,请根据实际安装情况替换路径。
      export LD_LIBRARY_PATH=/home/HwHiAiUser/Ascend/acllib/lib64
    4. 切换到可执行文件main所在的目录,例如“/home/HwHiAiUser/acl_vdec_resnet50/out”,给该目录下的main文件加执行权限。
      chmod +x main
    5. 切换到可执行文件main所在的目录,例如“/home/HwHiAiUser/acl_vdec_resnet50/out”,运行可执行文件。
      ./main

      可执行文件执行成功后,屏幕提示如下示例信息:

      ......
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_0, size=4000
      [INFO]  start check result file:./result/model_output_0
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_0.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_1, size=4000
      [INFO]  start check result file:./result/model_output_1
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_1.txt]
      [INFO]  result:classType[688],top1[0.596680],top5[0.901611]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_2, size=4000
      [INFO]  start check result file:./result/model_output_2
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_2.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_3, size=4000
      [INFO]  start check result file:./result/model_output_3
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_3.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_4, size=4000
      [INFO]  start check result file:./result/model_output_4
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_4.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_5, size=4000
      [INFO]  start check result file:./result/model_output_5
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_5.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_6, size=4000
      [INFO]  start check result file:./result/model_output_6
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_6.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_7, size=4000
      [INFO]  start check result file:./result/model_output_7
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_7.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_8, size=4000
      [INFO]  start check result file:./result/model_output_8
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_8.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  Process dvpp success
      [INFO]  model execute success
      [INFO]  output[0] DataBuffer, buffer addr = 0x10100007c000, buffer size = 4000
      [INFO]  memcopy output data from device to host buffer success.
      [INFO]  create output file success, filename=./result/model_output_9, size=4000
      [INFO]  start check result file:./result/model_output_9
      [INFO]  check result success, file exist
      [INFO]  reselut file: [./result/model_output_9.txt]
      [INFO]  result:classType[331],top1[0.908203],top5[1.000015]
      [INFO]  unload model success, modelId is 1
      [INFO]  execute sample success
      ......
      • 可执行文件运行过程中,VDEC解码成功后,模型推理前,会在main文件同级生成outdir目录,用于保存解码后的YUV420SP NV12格式的图片,推理结束后,系统会自动清理outdir目录。
      • 可执行文件执行成功后,同时会在main文件同级的result目录下生成结果文件,便于后期查看。*.h265格式的视频码流(仅包含一帧)被解码出一张YUV420SP NV12格式的图片,对该张图片做十次循环处理,包括缩放图片和模型推理,分别得到十张图片的推理结果:
        • model_output_*:模型推理结果的二进制文件。
        • model_output_*.txt:模型推理结果的txt文件。

分享:

    相关文档

    相关产品

close