models icon indicating copy to clipboard operation
models copied to clipboard

Squeezenet1.0 models give wrong prediction results

Open mingmingtasd opened this issue 1 year ago • 3 comments

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

mingmingtasd avatar Mar 15 '24 05:03 mingmingtasd

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

yuslepukhin avatar Apr 15 '24 18:04 yuslepukhin

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

Thanks, I open https://github.com/microsoft/onnxruntime/issues/20332

mingmingtasd avatar Apr 16 '24 08:04 mingmingtasd

@yuslepukhin I don't believe this is an ORT issue - it's an issue with the model file in the directory. Other models produce the correct results, but the SqueezeNet1.0 models produce the wrong results. Whoever added the model to the repo should investigate the source.

Zu-shi avatar Aug 29 '24 20:08 Zu-shi