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

Anyone succeed in converting pth to onnx format? #83

Closed
liamsun2019 opened this issue Feb 24, 2021 · 1 comment
Closed

Anyone succeed in converting pth to onnx format? #83

liamsun2019 opened this issue Feb 24, 2021 · 1 comment

Comments

@liamsun2019
Copy link

Hi Pals,

I tried to convert the trained pth model to onnx format, but encounter several issues. The code segment are as follows:

model = Trainer.build_model(cfg)
state = torch.load(cfg.MODEL.WEIGHTS, map_location=lambda storage, loc: storage)
model.load_state_dict(state['model'])
model.eval()
model.cuda()

must be 32-divisable

dummy_input = torch.randn(1, 3, 448, 448).to("cuda")
torch.onnx.export(model, dummy_input, "model.onnx", verbose=True, input_names=['image'], output_names=['pred'])

The used config file is centermask_lite_V_19_slim_dw_eSE_FPN_ms_4x.yaml.

a. The input to the network whose backbone is a rcnn is a list which contains dictionaries composed of input image data and some other attirbutes. Looks like there's no way to pass similar input for onnx exporting. I added a member function in rcnn.py (detectron2/modeling/meta_arch/rcnn.py) which accepts such input to solve this issue.

b. Based on above, following error rises up during conversion:
RuntimeError: Failed to export an ONNX attribute 'onnx::Sub', since it's not constant, please try to make things (e.g., kernel size) static if possible

I cannot google any clues to the error. Anyone can kindly help? Thanks.

@liamsun2019
Copy link
Author

reduplicated issue

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

1 participant