File size: 697 Bytes
8614e23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import onnxruntime as ort
from PIL import Image
import numpy as np

# Load the ONNX model
session = ort.InferenceSession('./saved-model/model.onnx')

# Get input and output names
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name

# Load and preprocess the image
img = Image.open('./training_images/shirt/00e745c9-97d9-429d-8c3f-d3db7a2d2991.jpg').resize((128, 128))
img_array = np.array(img).astype(np.float32) / 255.0  # Normalize pixel values to [0, 1]
img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension

# Run inference
outputs = session.run([output_name], {input_name: img_array})
print(f"Inference outputs: {outputs}")