Appearance
3.2.2 手写数字识别系统交互流程设计
python
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}")