运行应用

样例步骤适用于以下产品。

  • Atlas 200/300/500 推理产品
  • Atlas 推理系列产品
  • Atlas 训练系列产品

模型转换

  1. 以HwHiAiUser(运行用户)登录开发环境。
  2. 参见ATC工具使用指南中的ATC工具使用环境搭建,获取ATC工具并设置环境变量。
  3. 准备数据。

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

    • 从gitee上获取:单击Link,查看README.md,查找获取原始模型的链接。
    • 从GitHub上获取:单击Link,查看README.md,查找获取原始模型的链接。

  4. 将ResNet-50网络转换为适配昇腾AI处理器的离线模型(*.om文件),转换模型时,需配置色域转换参数,用于将YUV420SP格式的图片转换为RGB格式的图片。

    切换到“vpc_resnet50_imagenet_classification”目录,执行如下命令。Ascendxxx为使用的昇腾AI处理器型号,请用户自行替换。

    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”参数:生成的“resnet50_aipp.om”文件存放在“vpc_resnet50_imagenet_classification/model”目录下。
    • 使用atc命令时用户需保证对“vpc_resnet50_imagenet_classification”目录有写权限。

  5. 将Cast和ArgMaxD两个算子的算子描述信息(*.json文件)编译成适配昇腾AI处理器的离线模型(*.om文件),用于验证单算子的运行。

    切换到“vpc_resnet50_imagenet_classification”目录,执行如下命令。Ascendxxx为使用的昇腾AI处理器型号,请用户自行替换。

    atc --singleop=op_models/op_list.json --soc_version=Ascendxxx --output=op_models/
    • “--output”参数:生成的om文件必须放在“vpc_resnet50_imagenet_classification/op_models”目录下。
    • 使用atc命令时用户需保证对“vpc_resnet50_imagenet_classification”目录有写权限。

    关于各参数的详细解释,请参见ATC工具使用指南中的参数说明

  6. 以HwHiAiUser(运行用户)将开发环境的样例目录及目录下的文件上传到运行环境。

运行应用

  1. 登录运行环境。
  2. 准备测试数据。 请从以下链接获取该样例的输入图片,并以运行用户将获取的文件上传至开发环境的“vpc_resnet50_imagenet_classification/data”目录下。如果目录不存在,需自行创建。

  3. 参照环境变量配置完成运行环境的配置。
  4. “vpc_resnet50_imagenet_classification”路径下执行如下命令。

    python3 ./src/acl_sample.py

  5. 执行成功后,在屏幕上的关键提示信息示例如下

    Using device id:0
    model path:./model/resnet50_aipp.om
    images path:./data
    [Sample] init resource stage:
    [Sample] init resource stage success
    [Model] The class Model initializes resources:
    [Model] create output dataset:
    [Model] create output dataset success
    [Model] The class Model initializes resources successfully.
    [Sample] width:1024 height:683
    [Sample] image:./data/dog1_1024_683.jpg
    [Dvpp] vpc decode stage:
    [Dvpp] vpc decode stage success
    [Dvpp] vpc resize stage:
    [Dvpp] vpc resize stage success
    [Model] create model input dataset:
    [Model] create model input dataset success
    [Model] execute stage:
    [Model] execute stage success
    
    ======== top5 inference results: ========
    label:161  prob: 0.712891
    label:162  prob: 0.147095
    label:167  prob: 0.051636
    label:163  prob: 0.050476
    label:166  prob: 0.030136
    [SingleOP] single op cast success
    [SingleOp] get top 1 label success
    [SingleOP][ArgMaxOp] label of classification result is:161
    [Sample] width:1024 height:683
    [Sample] image:./data/dog2_1024_683.jpg
    [Dvpp] vpc decode stage:
    [Dvpp] vpc decode stage success
    [Dvpp] vpc resize stage:
    [Dvpp] vpc resize stage success
    [Model] create model input dataset:
    [Model] create model input dataset success
    [Model] execute stage:
    [Model] execute stage success
    
    ======== top5 inference results: ========
    label:267  prob: 0.855469
    label:266  prob: 0.049805
    label:219  prob: 0.032654
    label:265  prob: 0.013405
    label:129  prob: 0.011024
    [SingleOP] single op cast success
    [SingleOp] get top 1 label success
    [SingleOP][ArgMaxOp] label of classification result is:267
    [Model] The class Model releases resources successfully.
    [Dvpp] class Dvpp exit success
    [SingOp] class SingOp release source success
    [Sample] class Samle release source success