Skip to content

Error of input shape {0,32,1,1} when infer with generated onnx model #2312

Open
@DancingJane

Description

@DancingJane

I have already converted tensorflow model in ckpt into onnx, there is no error.
However, this error occurs when inferring with the generated onnx file

Traceback (most recent call last):
File "tf2onnx.py", line 438, in
onnx_infer(outfile)
File "tf2onnx.py", line 206, in onnx_infer
outputs = sess.run([], {sess.get_inputs()[0].name:input_img, sess.get_inputs()[1].name:input_fp, sess.get_inputs()[2].name:input_agl, sess.get_inputs()[3].name:phase_train})
File "/Users/jane/opt/anaconda3/envs/python37/lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 200, in run
return self._sess.run(output_names, input_feed, run_options)
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'Transpose__413' Status Message: /private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6klxfmwxo/croots/recipe/onnxruntime_1664948961123/work/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:41 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape &, onnxruntime::TensorShapeVector &, bool) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{0,32,1,1}, requested shape:{1,32,1,1}

the tf2onnx command is as follows:
python -m tf2onnx.convert
--checkpoint "./L.meta"
--inputs "inputs/input_img:0[1,48,64,3],inputs/input_fp:0[1,48,64,12],inputs/input_ang:0[1,2],model_control/phase_train:0"
--outputs "tower_1/warping_model/apply_lcm/Add:0"
--output "./onnx/onnxModel_direct_tf15_one_output_dynamic_4.onnx"
--opset 17

the inference code is as follows:
model = onnx.load(onnx_dir)
onnx.checker.check_model(model)
sess = onnxruntime.InferenceSession(onnx_dir)
input_img_shape = [1, 48, 64, 3] # Example shape, replace with the actual shape
input_img = np.random.normal(size=input_img_shape).astype(np.float32)
input_fp_shape = [1, 48, 64, 12]
input_fp = np.random.normal(size=input_fp_shape).astype(np.float32)
input_agl_shape = [1,2]
input_agl = np.random.normal(size=input_agl_shape).astype(np.float32)
phase_train = np.array(False, dtype=bool)
# Run the model (perform inference)
outputs = sess.run([sess.get_outputs()[0].name], {sess.get_inputs()[0].name:input_img, sess.get_inputs()[1].name:input_fp, sess.get_inputs()[2].name:input_agl, sess.get_inputs()[3].name:phase_train})

System information

  • OS Platform and Distribution (macOS 12.1):
  • TensorFlow Version: 15.0
  • Python version:3.7.15
  • ONNX version 1.13.0
  • ONNXRuntime version :1.12.1
  • tf2onnx: 1.16.1

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behaviorpending on user responseWaiting for more information or validation from user

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions