编译及运行应用

  1. 准备数据。

    1. 您可以从以下链接中获取ResNet-50网络的模型文件(*.prototxt)、预训练模型文件(*.caffemodel)。
      • ResNet-50网络的模型文件(*.prototxt):单击Link下载该文件。
      • ResNet-50网络的预训练模型文件(*.caffemodel):单击Link下载该文件。
    2. 参考ATC工具使用指南将ResNet-50网络转换为适配昇腾AI处理器的离线模型(*.om文件),转换模型时,需配置色域转换参数,用于将YUV420SP格式的图片转换为RGB格式的图片。

      切换到vdec_resnet50_classification样例目录,命令示例如下,从output参数设置的目录下获取om文件:

      atc --model=caffe_model/resnet50.prototxt --weight=caffe_model/resnet50.caffemodel --framework=0 --output=model/resnet50_aipp --soc_version=${soc_version} --insert_op_conf=caffe_model/aipp.cfg
      • --soc_version:昇腾AI处理器的版本,请根据实际情况替换。

        可从ATC安装路径的“atc/data/platform_config”目录下查看昇腾AI处理器的版本,对应“*.ini”文件的名字(不带.ini后缀)即为soc_version。

      • --output:生成的om文件建议命名为resnet50_aipp.om,并以管理员帐号将om文件上传到开发环境“样例目录\model”目录下,否则在编译代码前,您还需要修改sample_process.cpp中的omModelPath参数值。
        const char* omModelPath = "../model/resnet50_aipp.om";
    3. 准备输入视频码流。

      从以下链接获取输入视频码流文件,并以运行用户上传至开发环境“vdec_resnet50_classification样例目录/data”目录下。如果目录不存在,需自行创建。

      https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/models/aclsample/vdec_h265_1frame_rabbit_1280x720.h265

  2. 以管理员帐号登录开发环境,并切换到vdec_resnet50_classification样例所在的目录。
  3. 编译代码。

    1. 在样例目录下,创建目录用于存放编译文件,例如,本文中,依次创建的目录为“build\intermediates\soc”
    2. 以管理员身份执行cmd窗口,切换到“样例目录\build\intermediates\soc”目录下,执行cmake生成编译文件,在“样例目录\out\Debug”“样例目录\out\release”目录下生成可执行文件main.exe,将Debug或release目录下的main.exe复制到“样例目录\out”目录下,否则会导致运行可执行文件时找不到依赖的文件。

      “../../../src”表示CMakeLists.txt文件所在的目录,请根据实际目录层级修改。

      • Debug模式时的编译命令如下:
        cd 样例目录\build\intermediates\soc
        cmake ../../../src -DCMAKE_SKIP_RPATH=TRUE -G "Visual Studio 15 2017 Win64"
        cmake --build .
      • Release模式下的编译命令如下:
        cd 样例目录\build\intermediates\soc
        cmake ../../../src -DCMAKE_SKIP_RPATH=TRUE -G "Visual Studio 15 2017 Win64" -DCMAKE_CONFIGURATION_TYPES=release
        cmake --build . --config release

      当前样例的编码字符集为ASCII,编译命令默认都是ASCII编码字符集,不支持Unicode编码字符集,如需支持Unicode编码字符集,需用户自行适配代码。

  4. 运行应用。

    1. 以管理员帐号将开发环境的vdec_resnet50_classification样例目录及其子文件上传到运行环境(Host)。
    2. 以管理员帐号登录运行环境(Host)。
    3. 以管理员身份执行cmd窗口,切换到可执行文件main.exe所在的目录,运行可执行文件。
      main.exe

      可执行文件执行成功后,在屏幕上的关键提示信息示例如下:

      ......
      [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文件。