Intel® Distribution of OpenVINO™ Toolkit
Community support and discussions about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all things computer vision-related on Intel® platforms.

Convert custom pytorch BERT model?

Tye__Stephen
Beginner
569 Views

Is it possible to convert your own custom BERT model trained on Pytorch? I can see an example for a pre-trained BERT-NER model but I want to convert a custom model based on bert-base-cased.  I have converted my model to ONNX and have tried to run the mo.py but get this error:

[ ERROR ] Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.front.input_cut.InputCut'>): --input parameter was provided. Other inputs are needed for output computation. Provide more inputs or choose another place to cut the net.

 

Is what I am try to do even possible?

 

 

 

0 Kudos
11 Replies
Wan_Intel
Moderator
545 Views

Hi Tye_Stephen,

Thanks for reaching out.


Could you please share your model with us for further investigation?



Regards,

Wan


Tye__Stephen
Beginner
539 Views

You can download it from this link:

https://onnx-134.s3.amazonaws.com/bert-base-cased.onnx

 

Regards,

Stephen

Wan_Intel
Moderator
516 Views

Hi Tye_Stephen,

Thanks for your information.


I’ve encountered the same error as you did when I convert your ONNX model.


Therefore, please share your source model with us.


Also, please share the command of conversion to ONNX with us.



Thanks and regards,

Wan



Tye__Stephen
Beginner
501 Views

below is a link to the source pytorch bert-base-cased model:

 

https://onnx-134.s3.amazonaws.com/bertbasecased.tar.gz

 

 

Wan_Intel
Moderator
497 Views

Hi Tye_Stephen,

 

Thanks for sharing your source model with us.

 

We are investigating this issue and will update you at the earliest.

 

Regards,

Wan


Wan_Intel
Moderator
482 Views

Hi Tye_Stephen,


I have successfully converted your custom PyTorch bert-base-cased model into an ONNX file, then into Intermediate Representation using OpenVINO™ 2021.4 on Windows 10. You may refer to the steps below:


1.   Download the BERT_BASE model and copy the model_config.json file to your custom model directory.


2.   Steps to convert PyTorch bert-base-cased model to ONNX model is available on the following page:

https://docs.openvinotoolkit.org/2021.4/openvino_docs_MO_DG_prepare_model_convert_model_pytorch_spec...


3.   Steps to convert ONNX bert-base-cased model to IR is available on the following page:

https://docs.openvinotoolkit.org/2021.4/openvino_docs_MO_DG_prepare_model_convert_model_pytorch_spec...


For more information, please refer to the steps to convert PyTorch BERT-NER to the Intermediate Representation on the following page:

https://docs.openvinotoolkit.org/2021.4/openvino_docs_MO_DG_prepare_model_convert_model_pytorch_spec...


On another note, you may download the ONNX and IR files from this link.


Best regards,

Wan


Tye__Stephen
Beginner
463 Views

Thanks. 

Can you provide a python sample on how to pass a string of text to the IR file to get a classification?

Wan_Intel
Moderator
451 Views

Hi Tye_Stephen,


BERT Named Entity Recognition Python Demo is a demo application that reads command line parameters and loads a network to the Inference Engine. It also fetches data from the user-provided URL to populate the "context" text. The text is then used to search named entities.


Supported models for this demo application is available on the following page:

https://docs.openvinotoolkit.org/2021.4/omz_demos_bert_named_entity_recognition_demo_python.html#sup...


Best regards,

Wan


Tye__Stephen
Beginner
433 Views

I have looked through all the BERT demos you have provided and with some work I could probably modify them to work with my BERT sentiment classification model. But I think it would be good if you had a sentiment classification demo on your site as this type of BERT model is very common. It would be good if you could add such a demo to your roadmap.

Wan_Intel
Moderator
407 Views

Hi Tye_Stephen,

Thank you for offering your valuable advice.


We will help to consolidate this as a feature request to bring for engineering review.


Regards,

Wan


Wan_Intel
Moderator
330 Views

Hi Tye_Stephen,

 

This thread will no longer be monitored since we have provided suggestions.

If you need any additional information from Intel, please submit a new question.

 

Regards,

Wan


Reply