Skip to content

[ShapeInferenceError] Input tensor must have at least 2 dimensions #1982

@wwdok

Description

@wwdok

Hello, @rajeevsrao @pranavm-nvidia @borisfom, i am using onnx-graphsurgeon to isolate a subgraph, this is the code:

import onnx_graphsurgeon as gs
import numpy as np
import onnx

model = onnx.load("model_float32.onnx")
graph = gs.import_onnx(model)
tensors = graph.tensors()
graph.inputs = [tensors["input_1"].to_variable(dtype=np.float32) ]
graph.outputs = [tensors["output_mesh_identity"].to_variable(dtype=np.float32),tensors["conv_faceflag"].to_variable(dtype=np.float32)]
graph.cleanup()
onnx.save(gs.export_onnx(graph), "subgraph1.onnx")

this is the original onnx model:
model_float32.zip

this is the exported subgraph model:
subgraph1.zip

then i try to run the exported model with following code:

import onnxruntime
import numpy as np

model_path = 'subgraph1.onnx'
dummy_input = np.ones([1,192,192,3], dtype=np.float32)

session_option = onnxruntime.SessionOptions()

session = onnxruntime.InferenceSession(
    model_path,
    session_option,
    providers = [
        "CPUExecutionProvider"
    ]
)
input_name = session.get_inputs()[0].name
output_names = [o.name for o in session.get_outputs()]
input_shape = session.get_inputs()[0].shape
output = session.run(
    output_names,
    {input_name: dummy_input.transpose((0, 3, 1, 2))}
)

it reports error:

Traceback (most recent call last):
  File "c:\MachineLearning\PythonScripts\temp.py", line 13, in <module>
    "CPUExecutionProvider"
  File "C:\ProgramData\Anaconda3\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 335, in __init__
    self._create_inference_session(providers, provider_options, disabled_optimizers)
  File "C:\ProgramData\Anaconda3\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 370, in _create_inference_session
    sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from subgraph1.onnx failed:Node (Conv__840) Op (Conv) [ShapeInferenceError] Input tensor must have atleast 2 dimensions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions