Git Product home page Git Product logo

Comments (1)

blackpearl1022 avatar blackpearl1022 commented on September 12, 2024

@sulaimanvesal
The error message suggests that there is a mismatch in the expected dimensions for the BiasGelu node during the inference run. Specifically, the input tensor for this node is expected to have only one dimension, but it is receiving a tensor with four dimensions. This mismatch often occurs due to differences in tensor shapes between the PyTorch model and the ONNX representation.

Please try with the following approach to fix your issue.

  • Check Tensor Shapes: Ensure that the input tensors provided to the ONNX model have the correct shapes. You can print the shapes of the tensors in your PyTorch model before exporting to ONNX and compare them with the shapes expected by the ONNX model.

  • Simplify the ONNX Model: Use the onnx-simplifier to simplify the ONNX model, which can sometimes resolve issues related to complex node operations. Install the simplifier with pip install onnx-simplifier and run it on your model:

python3 -m onnxsim your_model.onnx your_model_simplified.onnx

  • Update ONNXRuntime: Ensure that you are using the latest version of ONNXRuntime, as bugs and issues are often fixed in newer releases.

  • Check Node Specifications: Verify the specifications of the BiasGelu node in your ONNX model. You can inspect the model using Netron or by parsing the ONNX model programmatically:

import onnx

model = onnx.load("your_model.onnx")
onnx.checker.check_model(model)
print(onnx.helper.printable_graph(model.graph))
  • Custom Operators: If BiasGelu is a custom operator or not standard in ONNX, you might need to handle its conversion explicitly or use a workaround.

  • Preprocessing: Ensure that any preprocessing steps applied during inference are consistent with those used during training and ONNX export.

I've attached the conceptional approach to check the tensor shapes before exporting to ONNX:

import torch
import onnx

# Your model definition
model = ...  # Load or define your ConvNeXt-V2 model
model.eval()

# Dummy input tensor with the same shape as your actual input
dummy_input = torch.randn(1, 3, 224, 224)

# Print the shape of the output tensor before exporting to ONNX
with torch.no_grad():
    output = model(dummy_input)
    print(f"Output shape before ONNX export: {output.shape}")

# Export the model to ONNX
torch.onnx.export(
    model,
    dummy_input,
    "model.onnx",
    export_params=True,
    opset_version=12,
    do_constant_folding=True,
    input_names=['input'],
    output_names=['output'],
    dynamic_axes={'input': {0: 'batch_size'}, 'output': {0: 'batch_size'}}
)

# Load and check the ONNX model
onnx_model = onnx.load("model.onnx")
onnx.checker.check_model(onnx_model)

Best luck !

from convnext-v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.