shabie / docformer

Implementation of DocFormer: End-to-End Transformer for Document Understanding, a multi-modal transformer based architecture for the task of Visual Document Understanding (VDU)
MIT License
255 stars 40 forks source link

Unable to convert model to onnx #38

Open blueprintparadise opened 2 years ago

blueprintparadise commented 2 years ago

Hi, I have been meaning to convert the final o/p of docformer in the document classification notebook from .ckpt to onnx but am unable to do so. I have tried the standard torch.onnx.export method but the issue lies in the "dummy_variable" input in the code. Can you please point me in the right direction.

model = DocFormer.load_from_checkpoint(CKPT_PATH)
model.eval() 

    # Let's create a dummy input tensor  

    # Export the model   
torch.onnx.export(model,         # model being run 
     #for_conversion,  
     maintup,
      #(input_ids,resized_scaled_img, x_features, y_features),         # model input (or a tuple for multiple inputs) 
     "ImageClassifier.onnx",       # where to save the model  
     export_params=True,  # store the trained parameter weights inside the model file 
     opset_version=10,    # the ONNX version to export the model to 
     do_constant_folding=True,  # whether to execute constant folding for optimization 
     input_names = ['resized_scaled_img', 'x_features', 'y_features', 'input_ids', 'resized_and_aligned_bounding_boxes', 'label'],   # the model's input names 
 # the model's output names 
                 ) 
print(" ") 
print('Model has been converted to ONNX') 
uakarsh commented 2 years ago

Hi there,

I have not explored much of ONNX, but I would explore it in a few days and would get back to you as soon as possible.

Regards, Akarsh

blueprintparadise commented 2 years ago

Hi @uakarsh any updates on the conversion. I have a few changes to the conversion code and managed the conversion. But this is the inference error.

NotImplemented: [ONNXRuntimeError] : 9 : NOT_IMPLEMENTED : Could not find an implementation for the node Clip_5:Clip(12)

Can you give me some input on how to tackle it.

uakarsh commented 2 years ago

Hi, I did the experiment with MLM here

Can you go through this, and let me know if this helps? Apologies for late reply