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

Convert custom pytorch BERT model?

Tye__Stephen
Beginner
1,801 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
1,777 Views

Hi Tye_Stephen,

Thanks for reaching out.


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



Regards,

Wan


0 Kudos
Tye__Stephen
Beginner
1,771 Views

You can download it from this link:

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

 

Regards,

Stephen

0 Kudos
Wan_Intel
Moderator
1,748 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



0 Kudos
Tye__Stephen
Beginner
1,733 Views

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

 

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

 

 

0 Kudos
Wan_Intel
Moderator
1,729 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


0 Kudos
Wan_Intel
Moderator
1,714 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_specific_Convert_Bert_ner.html#download_and_convert_the_model_to_onnx


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_specific_Convert_Bert_ner.html#convert_onnx_bert_ner_model_to_ir


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_specific_Convert_Bert_ner.html


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


Best regards,

Wan


0 Kudos
Tye__Stephen
Beginner
1,695 Views

Thanks. 

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

0 Kudos
Wan_Intel
Moderator
1,683 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#supported_models


Best regards,

Wan


0 Kudos
Tye__Stephen
Beginner
1,665 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.

0 Kudos
Wan_Intel
Moderator
1,639 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


0 Kudos
Wan_Intel
Moderator
1,562 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


0 Kudos
Reply