This model is designed for educational purposes, demos, and quick prototyping of ONNX-based image classification workflows.
1import onnxruntime as ort
2import numpy as np
3from PIL import Image
4
5# Load model
6session = ort.InferenceSession("resnet18_cifar10.onnx")
7
8# Preprocess image
9def preprocess(img_path):
10 img = Image.open(img_path).convert("RGB").resize((224, 224))
11 img_data = np.array(img).astype(np.float32) / 255.0
12 img_data = np.transpose(img_data, (2, 0, 1)) # CHW format
13 img_data = np.expand_dims(img_data, axis=0) # Batch dimension
14 return img_data
15
16input_data = preprocess("example.jpg")
17
18# Run inference
19outputs = session.run(None, {"input": input_data})
20pred_class = np.argmax(outputs[0])
21print("Predicted class:", pred_class)