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

After adding preprocessing steps to the model, on inference an error throws: Non-zero status code returned while running Add node. #20984

Closed
feff2 opened this issue Jun 10, 2024 · 4 comments
Labels
api issues related to all other APIs: C, C++, Python, etc. platform:windows issues related to the Windows platform

Comments

@feff2
Copy link

feff2 commented Jun 10, 2024

Describe the issue

I added preprocessing steps for TrOCR but now I get the following error: onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Add node. Name:'/embeddings/Add' Status Message: C:\a_work\1\s\onnxruntime\core/providers/cpu/math/element_wise_ops.h:560 onnxruntime::BroadcastIterator::Append axis == 1 || axis == largest was false. Attempting to broadcast an axis by a dimension other than 1. 386 by 578

To reproduce

This is my code, how i add it:
model = onnx.load("trocr_onnx/encoder_model.onnx")

inputs = [create_named_value('image', onnx.TensorProto.UINT8, ['num_bytes'])]
pipeline = PrePostProcessor(inputs, 18)

pipeline.add_pre_processing(
[
ConvertImageToBGR(),
Resize((384, 384), policy='not_larger'),
ChannelsLastToChannelsFirst(),
ImageBytesToFloat(),
Normalize([(0.5, 0.5), (0.5, 0.5), (0.5, 0.5)]),
Unsqueeze([0]),
]
)

modified_model = pipeline.run(model)
onnx.checker.check_model(modified_model)
onnx.save_model(modified_model, 'trocr_encoder.onnx')

Urgency

No response

Platform

Windows

OS Version

10

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.18.0

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@github-actions github-actions bot added the platform:windows issues related to the Windows platform label Jun 10, 2024
@feff2 feff2 changed the title After adding resize to the model, it gives an error After adding preprocessing steps to the model, it gives an error Jun 11, 2024
@sophies927 sophies927 added api issues related to all other APIs: C, C++, Python, etc. and removed platform:windows issues related to the Windows platform labels Jun 13, 2024
@feff2 feff2 changed the title After adding preprocessing steps to the model, it gives an error After adding preprocessing steps to the model, it gives an error: Non-zero status code returned while running Add node. Jun 17, 2024
@github-actions github-actions bot added the platform:windows issues related to the Windows platform label Jun 17, 2024
@feff2 feff2 changed the title After adding preprocessing steps to the model, it gives an error: Non-zero status code returned while running Add node. After adding preprocessing steps to the model, on inference an error throws: Non-zero status code returned while running Add node. Jun 17, 2024
@skottmckay
Copy link
Contributor

Hard to say without seeing the model. What was the expected input shape of the original model?

@feff2
Copy link
Author

feff2 commented Jun 19, 2024

expected input shape is 1x3x384x384
image

@skottmckay
Copy link
Contributor

Most likely your issue is this: Resize((384, 384), policy='not_larger'),

If the input image is square it should work. If it is not square, after the Resize the longest size will be 384 but the smallest will be less than that.

Typically you would do a centered crop or letterbox the resized image so that the original aspect ratio is maintained and the input is 384x384 as the model requires.

@feff2
Copy link
Author

feff2 commented Jun 21, 2024

thanks!

@feff2 feff2 closed this as completed Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api issues related to all other APIs: C, C++, Python, etc. platform:windows issues related to the Windows platform
Projects
None yet
Development

No branches or pull requests

3 participants