Convert to ONNX model
Hi @zhyever, Thanks for your great work! I'm curious if BinsFormer can be converted to ONNX model? If yes, please also provide sample code so we can verify it.
Thanks in advance!
I have implemented several codes to convert the model to ONNX but not release in this repo now. The most tricky issue is whether the ONNX has supported ops in models.
Relative codes can be like:
sample_input = torch.randn(1, 3, 480, 640)
input_nodes = ['input']
output_nodes = ['output']
print("\n\n\n Start export onnx")
# torch.onnx.export(model, sample_input, "model.onnx", export_params=True, input_names=input_nodes, output_names=output_nodes)
torch.onnx.export(model, sample_input, "nfs/model.onnx", export_params=True, input_names=input_nodes, output_names=output_nodes, opset_version=11)
# Converting model to Tensorflow
print("\n\n\n Start export_graph")
onnx_model = onnx.load("nfs/model.onnx")
Hi @zhyever ,
I'm just trying to convert BTS model to onnx. The issue is that the original pth model needs a dict as input (with following inference code:
data = {'img_metas': xxxx, 'img': xxxx}
pred = model(return_loss=False, **data),
which means the 'sample_input' in the following code should also be a dict
torch.onnx.export(model, sample_input, "nfs/model.onnx", export_params=True, input_names=input_nodes, output_names=output_nodes, opset_version=11)
However the torch.onnx.export module doesn't support a dict as input. Do you know how to fix this? Thanks a lot.
Sorry for the late reply, I missed your questions. Yes, the input of the model during converting should be single. In other words, the forward function should be like: def forward(self, x). No more parameters are supported. Before you convert the model, you should hack a def forward(self, x) in the depther, so that the converter can successfully pass variables.
Thanks for your reply. I'll check that.
Close for now.
@ReBoRn8888 Hi, I am also trying to convert the model to ONNX. However, I encounter the error like below. Do you have any experiences to deal with that?
