onnx-->hefONNXRuntimeError

Hello, I have tested the onnx model I transferred out and completed the onnx runtime, but there is an error message when transferring it to hef. Can you tell me how to solve it?
ONNX shape inference failed: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Non-zero status code returned while running GridSample node. Name:'/head/layers.2/GridSample_3' Status Message: Only 4-D tensor is supported

Regardless of this error, GridSample is not supported by DFC.

Hey @chenyao,

As @lawrence mentioned, GridSample is only supported without shape inference. The error you’re seeing - “GridSample ONNX shape inference failed: … GridSample … Only 4-D tensor is supported” - means the translator found a GridSample node with inputs that aren’t 4-dimensional (N×C×H×W format), and ONNX Runtime can’t figure out the shapes.

Switch to the Resize operator Hailo’s Dataflow Compiler works well with the ONNX Resize operator (it even supports 4-bit mode), but it doesn’t like GridSample. If you’re working with a PyTorch model, you can replace any instances of:

F.grid_sample(x, grid, …)

with:

F.interpolate(x, size=(out_h, out_w), mode='bilinear', align_corners=False)

This change will make your model export to an ONNX Resize node instead, which the compiler will happily accept and compile.

This should resolve your shape inference issues. Let me know if you run into any other problems!

1 Like

OK,thanks!I am currently facing a problem. I encountered an error while performing hex conversion on the transferred onnx, as follows.
[warning] Cannot use graphviz, so no visualizations will be created
2025-07-30 16:45:09,650 - INFO - Starting ONNX to HEF conversion process…
2025-07-30 16:45:09,657 - INFO - ✅ Initialized ClientRunner with hardware architecture: hailo8
2025-07-30 16:45:09,657 - INFO - ✅ ONNX model file found: /home/ubuntu/ycy/Sparse4D-3.0/onnx_models/single_frame_decoder.onnx
2025-07-30 16:45:09,657 - INFO - Translating ONNX model to HAR…
[info] Translation started on ONNX model single_frame_decoder
[info] Restored ONNX model single_frame_decoder (completion time: 00:00:00.05)
[info] Extracted ONNXRuntime meta-data for Hailo model (completion time: 00:00:00.19)
[info] Simplified ONNX model for a parsing retry attempt (completion time: 00:00:08.81)
2025-07-30 16:45:22,418 - ERROR - ❌ Failed to translate ONNX model to HAR: Couldn’t find inputs from ONNX proto. Number of expected inputs: 6, Inputs found: 2

But I have checked that the input for the conversion to Hef is consistent with the model. Is it because the model input uses dynamic axes?

This is the right place you have found. Request Early Access to DeGirum's Cloud Compiler apply for early access here. then after approval you can easily convert the .pt to .hef as i did. and the conversion takes a few minutes

Does that mean the reason is because I used real data to generate ONNX?

@Emmanuel_Laryea

Thank you for suggesting DeGirum cloud compiler. Unfortunately, the cloud compiler currently is restricted to YOLO models and cannot be used to compile the above model.

@chenyao

You can still request access to cloud compiler if you need to compile any YOLO models.