后处理

功能介绍

一般情况下,获取模型文件时,会带有后处理的代码文件,建议使用和模型训练时一致的后处理流程,从而保证推理结果符合预期。

对于不同的经典模型,MindSDK封装了不同的后处理函数,可实现不同模型的后处理操作,将模型推理后的数据直接传入后处理接口,得到最终结果,极大地简化了使用过程。

相关接口说明请参考模型后处理

接口调用流程图

以ResNet-50后处理为例:

图1 接口调用流程图

示例代码

基于MindSDK后处理函数(ResNet-50)的示例如下,不可以直接拷贝运行,仅供参考:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 以Resnet50为例,模型输出为output
# 步骤1: 获取后处理对象,并加载配置信息和标签信息
postprocessor = post.Resnet50PostProcess(config_path=config_path, label_path=label_path) 

# 步骤2:将模型输出送入后处理接口process函数
pred = postprocessor.process([output])[0][0]  # pred:<ClassInfo classId=... confidence=... className=...>

# 步骤3:获取结果
confidence = pred.confidence  # 获取类别置信度
className = pred.className  # 获取类别名称
print('{}: {}'.format(className, confidence))  # 打印出结果