Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squeezenet1.0 models give wrong prediction results #659

Open
mingmingtasd opened this issue Mar 15, 2024 · 2 comments
Open

Squeezenet1.0 models give wrong prediction results #659

mingmingtasd opened this issue Mar 15, 2024 · 2 comments
Labels

Comments

@mingmingtasd
Copy link

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
Copy link

ONNX is a standard. You should probably file an issue against onnxruntime.

@mingmingtasd
Copy link
Author

ONNX is a standard. You should probably file an issue against onnxruntime.

Thanks, I open microsoft/onnxruntime#20332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants