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

please provide source code to export onnx file #106

Open
ChengLiu-xsy opened this issue Dec 15, 2023 · 2 comments
Open

please provide source code to export onnx file #106

ChengLiu-xsy opened this issue Dec 15, 2023 · 2 comments

Comments

@ChengLiu-xsy
Copy link

hi:
Could you please provide the source code of exporting onnx file?

@BADAL244
Copy link

import torch
from lib.model_test import D2Net
from lib.utils import preprocess_image
from lib.pyramid import process_multiscale

CUDA

use_cuda = torch.cuda.is_available()
device = torch.device("cuda:0" if use_cuda else "cpu")

Initialize the model

model_file = '/home/badal/d2-net/d2_tf.pth' # Specify the path to your model file
use_relu = True # Specify whether to use ReLU

model = D2Net(
model_file=model_file,
use_relu=use_relu,
use_cuda=use_cuda
)

Ensure the model is in evaluation mode

model.eval()

dummy_input = torch.randn(1, 3, 480, 640, device=device)

Specify the path to save the ONNX model

onnx_file_path = '/home/badal/d2-net/onnx/model_new.onnx'

Export the model

torch.onnx.export(model, dummy_input, onnx_file_path, export_params=True, opset_version=11,
input_names=['input'], output_names=['descriptor' , 'score' , 'keypoint' ])

print(f"Model has been converted to ONNX and saved to {onnx_file_path}")

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