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

pth to ONNX #36

Open
lhehejunl opened this issue Apr 24, 2023 · 1 comment
Open

pth to ONNX #36

lhehejunl opened this issue Apr 24, 2023 · 1 comment

Comments

@lhehejunl
Copy link

Hi,bigcow, can you provide the code which model.pth convert to model.onnx? thanks.

@MinGiSa
Copy link

MinGiSa commented Jan 5, 2024

from archs import UNext
import torch

if name == 'main':
with torch.no_grad():
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = UNext(1,3,False).to(device)
checkpointPath = "Your Model File Path"
destPath = "Save Path, You Want"
model.load_state_dict(torch.load(checkpointPath))
model.eval()

    imgHeight = 256
    imgWidth = 256
    batchSize = 1
    dummyInput = torch.rand(batchSize, 3, imgHeight, imgWidth).to(device)
    inputNames = ["input"]
    outputNames = ["output"]
    dynamicAxes = {"input": {0: "batchSize"}, "output": {0: "batchSize"}}

    torch.onnx.export(model,
                        dummyInput,
                        destPath,
                        input_names=inputNames,
                        output_names=outputNames,
                        dynamic_axes=dynamicAxes,
                        verbose=True)

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

2 participants