当前位置: 首页> 健康> 养生 > 海思Ascend精度分析详细操作指南

海思Ascend精度分析详细操作指南

时间:2025/8/24 7:21:32来源:https://blog.csdn.net/u012374012/article/details/139632156 浏览次数:0次

1.简介

        海思平台在转模型量化时经常需要精度分析,可以参考官方文档《精度比对工具使用指南.pdf》,但是里面的一些细节描述还是不清楚,因此本文详细描述了精度分析对比的操作指南,方便新手入门。

2.对原始未量化的onnx模型进行dump

说明:原始模型为caffe的dump方法参考之前的博客

(1)准备工作

        使用精度比对工具前,请参考《驱动和开发环境安装指南》手册完成开发环境搭建。本文这里不再赘述。

(2)使用脚本将图片数据转成可以用来dump的bin文件

        脚本文件:

import os
import numpy as np
import cv2
def cv2_imread(path):img = cv2.imdecode(np.fromfile(path, dtype=np.uint8), 1)return imgdef cv2_imwrite(image, image_path, type='jpg'):cv2.imencode('.{}'.format(type), image)[1].tofile(image_path)data_sets = []
sample_batch_input_bin_dir = "./"
for item in os.listdir(sample_batch_input_bin_dir):if not item.endswith(".jpg"):continueprint(item)img = cv2_imread(item)img = img[:, :, ::-1] #BGR2RGBnw = 640nh = 640img = cv2.resize(img, (nw, nh))#original_input_data = np.fromfile(img, dtype=np.uint8) # 读取bin文件时,bin文件内的dtype类型须根据模型的输入类型确定,下面以float32为例# 将数据重新组织,具体根据模型输入中的shape值确定#img.astype(np.float32)/ 255img = img/255.0img.astype(np.float32)img = np.float32(img)#print(img)current_input_data = np.transpose(img, [2,0,1])#current_input_data = img.reshape(3,640, 640)# 将当前的数据添加到列表中data_sets.append(current_input_data)# 将每个batch的数据保存到一个输入bin文件中,从而得到一个包含多batch的输入bin文件np.array(data_sets).tofile("input.bin")

(3)使用onnx_dump脚本对(2)生

关键字:海思Ascend精度分析详细操作指南

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: