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 #20332

Open
mingmingtasd opened this issue Apr 16, 2024 · 5 comments
Open

Squeezenet1.0 models give wrong prediction results #20332

mingmingtasd opened this issue Apr 16, 2024 · 5 comments
Labels
ep:WebNN WebNN execution provider platform:web issues related to ONNX Runtime web; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot

Comments

@mingmingtasd
Copy link

mingmingtasd commented Apr 16, 2024

Describe the issue

Move the onnx/models#659 here:

All squeezenet 1.0 models from https://github.com/onnx/models/tree/main/validated/vision/classification/squeezenet can't provide correct prediction results.

To reproduce

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

You can also use onnxruntime web demo to reproduce: use squeezenet 1_0 rather than 1_1 in https://github.com/microsoft/onnxruntime-web-demo/blob/main/src/components/models/Squeezenet.vue

Platform

Windows

OS Version

11

@github-actions github-actions bot added ep:DML issues related to the DirectML execution provider platform:web issues related to ONNX Runtime web; typically submitted using template platform:windows issues related to the Windows platform labels Apr 16, 2024
@fdwr
Copy link
Contributor

fdwr commented Apr 16, 2024

@mingmingtasd This is marked as "EP == DirectML", but shouldn't this be the WebNN EP? I'm confused by the issue because it includes Python code, points to an onnxruntime web demo link for the repro, but also says DML EP (which isn't used in ORTW).

@mingmingtasd
Copy link
Author

@mingmingtasd This is marked as "EP == DirectML", but shouldn't this be the WebNN EP? I'm confused by the issue because it includes Python code, points to an onnxruntime web demo link for the repro, but also says DML EP (which isn't used in ORTW).

I firstly opened an issue : onnx/models#659 , but someone told me to open the issue to onnxruntime. Sorry for confusion, I give the onnxruntime web demo and python code mainly to provide two ways to reproduce.

@mingmingtasd
Copy link
Author

The label should be webnn ep, but it seems I can't change the label...

@fdwr fdwr added ep:WebNN WebNN execution provider and removed ep:DML issues related to the DirectML execution provider labels Apr 17, 2024
@fdwr
Copy link
Contributor

fdwr commented Apr 17, 2024

The label should be webnn ep, but it seems I can't change the label...

I guess you have to be part of microsoft/onnxruntime to change labels - I changed it 👍.

Did you already compare against the CPU EP and DML EP, and did those return different results than the WebNN EP? If so, then @Honry will want to be aware.

@sophies927 sophies927 removed the platform:windows issues related to the Windows platform label Apr 25, 2024
Copy link
Contributor

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:WebNN WebNN execution provider platform:web issues related to ONNX Runtime web; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

3 participants