Mobilenet does not accept batched inputs
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 9.8k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
Bug Report
Which model does this pertain to?
Describe the bug
The documentation of mobilenet says that the expected input shape is (N x 3 x H x W), where N is the batch size, and H and W are expected to be at least 224.
But when downloading the mobilenetv2-7.onnx model and running a simple inference session on it, it fails when running on any batch size > 1
Reproduction instructions
System Information
OS Platform and Distribution: Ubuntu 22.04.5 LTS
ONNX version: 1.17.0
Backend/Runtime version: onnxruntime 1.21.0
Provide a code snippet to reproduce your errors.
import onnxruntime
import requests
import numpy as np
MODEL_PATH = 'mobilenet.onnx'
model_url = "https://github.com/onnx/models/raw/refs/heads/main/validated/vision/classification/mobilenet/model/mobilenetv2-7.onnx"
# Download the model
response = requests.get(model_url)
with open(MODEL_PATH, 'wb') as f:
f.write(response.content)
# Load model
sess = onnxruntime.InferenceSession(MODEL_PATH)
input_name = sess.get_inputs()[0].name
input_shape = sess.get_inputs()[0].shape
input_type = sess.get_inputs()[0].type
print("Input shape:", input_shape)
print("Input type:", input_type)
# Create a batched input (batch size = 4)
batched_input = np.random.rand(4, 3, 224, 224).astype(np.float32)
# Try inference - should raise an error
try:
output = sess.run(None, {input_name: batched_input})
except Exception as e:
print("\n❌ Inference failed with batched input:")
print(e)
Result
❌ Inference failed with batched input:
[ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: data for the following indices
index: 0 Got: 4 Expected: 1
Please fix either the inputs/outputs or the model.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the linked validated/vision/classification/mobilenet/ directory and inspect the mobilenetv2-7.onnx input metadata. Run the provided Python reproduction with onnxruntime using a batch larger than one. Done means the model accepts the documented (N, 3, H, W) input and the documentation matches the verified behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100