ITADN

Mobilenet does not accept batched inputs

#680OpenRohanjames1997 创建于 2025-04-18
bug
R
Rohanjames1997commented
# Bug Report ### Which model does this pertain to? [Mobilenet](https://github.com/onnx/models/tree/main/validated/vision/classification/mobilenet/) ### Describe the bug The [documentation](https://github.com/onnx/models/tree/main/validated/vision/classification/mobilenet#input) 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) ``` ### Notes Any additional information
0 条评论