Examples for using ONNX Runtime for machine learning inferencing.
MIT License
1.07k
stars
312
forks
source link
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running ReduceMax node. Name:'488_ReduceMax' Status Message: #447
def _preprocess_images(images_folder: str, height: int, width: int, size_limit=0):
"""
Loads a batch of images and preprocess them
parameter images_folder: path to folder storing images
parameter height: image height in pixels
parameter width: image width in pixels
parameter size_limit: number of images to load. Default is 0 which means all images are picked.
return: list of matrices characterizing multiple images
"""
image_names = os.listdir(images_folder)
if size_limit > 0 and len(image_names) >= size_limit:
batch_filenames = [image_names[i] for i in range(size_limit)]
else:
batch_filenames = image_names
unconcatenated_batch_data = []
def _preprocess_images(images_folder: str, height: int, width: int, size_limit=0): """ Loads a batch of images and preprocess them parameter images_folder: path to folder storing images parameter height: image height in pixels parameter width: image width in pixels parameter size_limit: number of images to load. Default is 0 which means all images are picked. return: list of matrices characterizing multiple images """ image_names = os.listdir(images_folder) if size_limit > 0 and len(image_names) >= size_limit: batch_filenames = [image_names[i] for i in range(size_limit)] else: batch_filenames = image_names unconcatenated_batch_data = []
class DataReader(CalibrationDataReader): def init(self, calibration_image_folder: str, model_path: str): self.enum_data = None
input_model_path = '/home/fanshao/mmlab/mmyolo-0.6.0/projects/easydeploy/tools/work_dir/best_coco_bbox_mAP_epoch_300.onnx' # 输入onnx模型 output_model_path = '/home/fanshao/mmlab/mmyolo-0.6.0/projects/easydeploy/tools/work_dir/int8.onnx' # 输出模型名 calibration_dataset_path = '/home/fanshao/mmlab/mmyolo-0.6.0/projects/easydeploy/tools/calibration_img' # 校准数据集图像地址
用于校准数据加载,注意这个方法里面需要做图像一些操作,与pytorch训练的时候加载数据操作一致
dr = DataReader(calibration_dataset_path, input_model_path)
开始量化
quantize_static( input_model_path, output_model_path, dr, quant_format=QuantFormat.QDQ, weight_type=QuantType.QUInt8, )