issue1038 / python /test_image.py
jrsimuix's picture
scripts to validate and test
8614e23 verified
raw
history blame contribute delete
697 Bytes
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}")