Squeezenet1.0 models give wrong prediction results
mingmingtasd opened this issue · 3 comments
mingmingtasd commented
Bug Report
Which model does this pertain to?
All squeezenet 1.0 models from https://github.com/onnx/models/tree/main/validated/vision/classification/squeezenet
Describe the bug
These squeezenet 1.0 models can't provide correct prediction results:
Reproduction instructions
System Information
Win11
Select any one squeezenet 1.0 model to try:
import onnx
import onnxruntime
import numpy as np
from PIL import Image
# Load SqueezeNet ONNX
model_path = 'squeezenet1.0-12-fp32.onnx'
model = onnx.load(model_path)
# Create ONNX session
session = onnxruntime.InferenceSession(model_path)
# Load image
image_path = 'dog.jpg'
image = Image.open(image_path)
image = image.resize((224, 224))
# Image preprocessing
image = np.array(image).astype(np.float32)
image /= 255.0
# Normalize image
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
image = (image - mean) / std
image = np.transpose(image, (2, 0, 1)) # Adjust channel order of the image
image = np.expand_dims(image, axis=0) # Add batch dimension
# convert the input tensor to float type
image = image.astype(np.float32)
# Predict
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
input_feed = {input_name: image}
output = session.run([output_name], input_feed)
# Load the labels file
labels_path = 'synset.txt'
with open(labels_path, 'r') as f:
labels = f.read().splitlines()
# Get results
predicted_idx = np.argmax(output[0])
predicted_label = labels[predicted_idx]
print("Predicted label:", predicted_label)
...
The prediction result is always:
Predicted label: n03788365 mosquito net
yuslepukhin commented
ONNX is a standard. You should probably file an issue against onnxruntime.
mingmingtasd commented
ONNX is a standard. You should probably file an issue against onnxruntime.
Thanks, I open microsoft/onnxruntime#20332