Skip to content

3.2.2 手写数字识别系统交互流程设计 ​

python0/12 已填
import onnxruntime
import numpy as np
from PIL import Image


# 加载ONNX模型  2分
ort_session = 


# 加载图像 2分
image = ('L')  # 转为灰度图


#图像预处理
image = ((28, 28))  # 调整大小为MNIST模型的输入尺寸2分
image_array = (, dtype=np.float32)  # 转为numpy数组2分
image_array = (, axis=0)  # 添加batch维度2分
image_array = (, axis=0)  # 添加通道维度2分


#返回模型输入列表 2分
ort_inputs = {()[0].name: image_array}
# 执行预测 2分
ort_outs = (None, ort_inputs)


# 获取预测结果 2分
predicted_class = 


# 输出预测结果
print(f"Predicted class: {predicted_class}")

上海人工智能训练师(三级)实训 · 40 个实战任务