Efficientnet

本示例展示如何把efficientnet模型量化编译,最后部署到后摩芯片的设备上。

模型说明

本例使用的 efficientnet 实现来自 github 开源项目https://github.com/NVIDIA/DeepLearningExamples。

可以通过以下代码从原始途径获取模型:

import torch
efficientnet = torch.hub.load(
    'NVIDIA/DeepLearningExamples:torchhub',
    'nvidia_efficientnet_b0', pretrained=True)
input = torch.randn([1, 3, 224, 224])
torch.onnx.export(efficientnet, input, 'efficientnet_b0_224x224.onnx', opset_version=13)

本模型int8精度不佳,需要混合量化。本示例已使用混合量化配置,所以性能方面有所损失。

快速开始

可以通过hmatc工具一键执行性能测试和精度测试,详细介绍请参考houmo-examples根目录下README.md文件的快速上手章节。 校准使用的 ImageNet 2012 数据集需自行从官方渠道下载,下载方式请参考数据集说明 (../../../data/datasets/README.md)。

精度评估

量化

hmatc quant -c config.yml -t xh2       # 芯片

编译

hmatc build -c config.yml -t xh2       # 芯片

精度评估

hmatc eval -c config.yml -t xh2          # 芯片
hmatc eval -c config.yml -t xh2  --onnx  # onnx

执行完成后会打印模型的数据集精度信息。

性能评估

hmatc perf -c config.yml -t xh2 -wn 10 -sn 1000 -tn 4

执行完成后会打印模型推理延迟、吞吐量等信息。

结果演示

本示例依赖hmatc演示结果,在编译完成的基础上执行:

hmatc demo -c config.yml -t xh2

执行完成后会打印模型的分类结果信息。

参考结果

精度结果

# onnx
'input_size': [1, 3, 224, 224], 'dataset': 'ILSVRC_2012Val', 'num': 50000, 'top1_acc': '0.750500'
# xh2
'input_size': [1, 3, 224, 224], 'dataset': 'ILSVRC_2012Val', 'num': 50000, 'top1_acc': '0.726800'

性能结果

[Latency] Inference  avg:  12.867 ms, max:  19.161 ms, min:   6.555 ms, tp99:  13.217 ms, tp999:  19.161 ms
[Latency] Input      avg:   0.301 ms, max:   0.480 ms, min:   0.139 ms, tp99:   0.445 ms, tp999:   0.480 ms
[Latency] Output     avg:   0.086 ms, max:   0.250 ms, min:   0.012 ms, tp99:   0.228 ms, tp999:   0.250 ms
[Latency] End2end    avg:  13.254 ms, max:  19.574 ms, min:   6.875 ms, tp99:  13.513 ms, tp999:  19.574 ms
[Throughput] total: 3356.330 ms, avg: 3.356 ms, repeat: 1000, rounds: 1
[Throughput] qps: 297.944