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

how to convert the pth file to onnx? #114

Open
youzipi opened this issue Mar 20, 2024 · 2 comments
Open

how to convert the pth file to onnx? #114

youzipi opened this issue Mar 20, 2024 · 2 comments

Comments

@youzipi
Copy link

youzipi commented Mar 20, 2024

how to convert the pth file to onnx?

@gaurav0651
Copy link

@farazBhatti
Copy link

import torch
device='cpu'
input_shape = (1,3, 512, 512)

# Create a dummy input tensor with random values (you should use actual data)
sample_input = torch.randn(input_shape).to(device)
model_path = "isnet-general-full_model.pth"

# Load the traced model
model = torch.load(model_path,map_location=device)
# Ensure that the model is in evaluation mode
model.eval()
onnx_model_path='isnet-onnx-model.onnx'
torch.onnx.export(
    model,                  # PyTorch Model
    sample_input,                    # Input tensor
    onnx_model_path,        # Output file (eg. 'output_model.onnx')
    opset_version=12,       # Operator support version
    input_names=['input'] ,  # Input tensor name (arbitary)
    output_names=['output'] # Output tensor name (arbitary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants