引言
O6搭载的CIX P1 12核Armv9处理器配合30TOPS算力的NPU和高性能GPU,非常适合AI模型端侧部署。阿里云文字识别OCR(读光OCR),是一款由阿里巴巴达摩院打造的OCR产品,用于识别图片、文档、卡证等文件所包含的文字信息。该产品具备完善的图像检测、文字识别和文字理解的能力。在本篇文章中将使用O6部署这款OCR模型。
硬件要求
- "星睿O6" AI PC开发板
软件要求
- ubuntu 20.04
- CIX NOE SDK
模型部署步骤
onnx模型准备
参考https://github.com/MGzhou/dug...,下载onnx模型,包括(det.onnx和rec.onnx),det.onnx用来检测图片中的文字框,rec.onnx用来识别框中的文字。
det.onnx量化
detbuild.cfg
[Common]
mode = build
[Parser]
model_type = ONNX
model_name = det
detection_postprocess =
model_domain = OBJECT_DETECTION
input_data_format = NCHW
input_model = model/det.onnx
input = images
input_shape = [1, 3, 512, 512]
output_dir = ./out
[Optimizer]
dataset = numpydataset
calibration_data = datasets/detect_cal.npy
calibration_batch_size = 1
output_dir = ./out
dump_dir = ./out
quantize_method_for_activation = per_tensor_asymmetric
quantize_method_for_weight = per_channel_symmetric_restricted_range
save_statistic_info = True
[GBuilder]
target = X2_1204MP3
outputs = det.cix
tiling = fps
rec.onnx量化
[Common]
mode = build
[Parser]
model_type = ONNX
model_name = rec
detection_postprocess =
model_domain = OBJECT_DETECTION
input_data_format = NCHW
input_model = model/rec.onnx
input = images
input_shape = [3, 3, 32, 300]
output = pred
output_shape = [3, 75,7644]
output_dir = ./out
[Optimizer]
dataset = numpymultiinputwithoutbatchdimdataset
without_batch_dim = True
calibration_data = datasets/rec_cal.npz
calibration_batch_size = 1
output_dir = ./out
dump_dir = ./out
quantize_method_for_activation = per_tensor_asymmetric
quantize_method_for_weight = per_channel_symmetric_restricted_range
save_statistic_info = True
[GBuilder]
target = X2_1204MP3
outputs = rec.cix
使用NPU进行推理
推理结果
推理性能
det | rec | |
---|---|---|
cpu(onnx) | 347ms | 58ms |
npu(noe) | 5.9ms | 4.6ms |
这里的rec时间是对单个检测框识别的,一张图片所需要的识别时间和文字框数量成正比。
结语
总体来说,使用O6 NPU能够快速且准确的运行读光OCR模型,相比于CPU性能提升显著