Skip to content

Commit

Permalink
add tutorial for PyTorch model conversion (#1168)
Browse files Browse the repository at this point in the history
* add tutorial for PyTorch model conversion

* typos, colab adoption, code style

* add colab badge
  • Loading branch information
eaidova authored Jul 5, 2023
1 parent 58b72df commit 1e48df3
Show file tree
Hide file tree
Showing 6 changed files with 967 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Tutorials that explain how to optimize and quantize models with OpenVINO tools.
| Notebook | Description |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |:----------------------------------------------------------------------------------------------------------------------------|
| [101-tensorflow-classification-to-openvino](notebooks/101-tensorflow-classification-to-openvino/)<br>[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F101-tensorflow-classification-to-openvino%2F101-tensorflow-classification-to-openvino.ipynb) | Convert TensorFlow models to OpenVINO IR |
| [102-pytorch-onnx-to-openvino](notebooks/102-pytorch-onnx-to-openvino/) | Convert PyTorch models to OpenVINO IR |
| [102-pytorch-to-openvino](notebooks/102-pytorch-to-openvino/)<br>[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/eaidova/openvino_notebooks/blob/ea/pt_tutorial/notebooks/102-pytorch-to-openvino/102-pytorch-to-openvino.ipynb) | Convert PyTorch models to OpenVINO IR |
| [103-paddle-to-openvino](notebooks/103-paddle-to-openvino/)<br>[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F103-paddle-to-openvino%2F103-paddle-to-openvino-classification.ipynb) | Convert PaddlePaddle models to OpenVINO IR |
| [104-model-tools](notebooks/104-model-tools/)<br>[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F104-model-tools%2F104-model-tools.ipynb) | Download, convert and benchmark models from Open Model Zoo |
| [105-language-quantize-bert](notebooks/105-language-quantize-bert/) | Optimize and quantize a pre-trained BERT model |
Expand Down
2 changes: 1 addition & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Jupyter notebooks 分为四个大类,选择一个跟你需求相关的开始
| Notebook | Description |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------- |
| [101-tensorflow-classification-to-openvino](notebooks/101-tensorflow-classification-to-openvino/)<br>[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F101-tensorflow-classification-to-openvino%2F101-tensorflow-classification-to-openvino.ipynb) | 转换 TensorFlow模型为OpenVINO IR |
| [102-pytorch-onnx-to-openvino](notebooks/102-pytorch-onnx-to-openvino/) | 转换PyTorch模型为OpenVINO IR |
| [102-pytorch-to-openvino](notebooks/102-pytorch-to-openvino/) | 转换PyTorch模型为OpenVINO IR |
| [103-paddle-to-openvino](notebooks/103-paddle-to-openvino/)<br>[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F103-paddle-to-openvino%2F103-paddle-to-openvino-classification.ipynb) | 转换PaddlePaddle模型为OpenVINO IR |
| [104-model-tools](notebooks/104-model-tools/)<br>[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F104-model-tools%2F104-model-tools.ipynb) | 从Open Model Zoo进行模型下载,转换以及进行基线测试 |
| [105-language-quantize-bert](notebooks/105-language-quantize-bert/) | 优化及量化BERT预训练模型 |
Expand Down
16 changes: 0 additions & 16 deletions notebooks/102-pytorch-onnx-to-openvino/README.md

This file was deleted.

941 changes: 941 additions & 0 deletions notebooks/102-pytorch-to-openvino/102-pytorch-to-openvino.ipynb

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions notebooks/102-pytorch-to-openvino/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# PyTorch to OpenVINO™ IR Tutorial

This tutorial demonstrates how to convert PyTorch models to OpenVINO Intermediate Representation (IR) format.

## Notebook Contents

* [102-pytorch-to-openvino](./102-pytorch-to-openvino.ipynb) shows how to convert the Pytorch model in formats `torch.nn.Module` and `torch.jit.ScriptModule` into OpenVINO Intermediate Representation. The tutorial uses [RegNetY_800MF](https://arxiv.org/abs/2003.13678) model from [torchvision](https://pytorch.org/vision/stable/index.html) pre-trained on [ImageNet](https://www.image-net.org/) dataset to demonstrate how to convert PyTorch models to OpenVINO Intermediate Representation using [Model Optimizer](https://docs.openvino.ai/2023.0/openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html). It also shows how to do classification inference on an image, using [OpenVINO Runtime](https://docs.openvino.ai/nightly/openvino_docs_OV_UG_OV_Runtime_User_Guide.html) and compares the results of the PyTorch model with the OpenVINO IR model.

[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/eaidova/openvino_notebooks/blob/ea/pt_tutorial/notebooks/102-pytorch-to-openvino/102-pytorch-to-openvino.ipynb)
![classification_result](https://user-images.githubusercontent.com/29454499/250586825-2a4a74a6-e091-4e47-8f29-59a72fe4975f.png)


* [102-pytorch-onnx-to-openvino](./102-pytorch-onnx-to-openvino.ipynb) shows how to convert the PyTorch model to OpenVINO IR with the intermediate step of exporting PyTorch model to ONNX format.

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F102-pytorch-onnx-to-openvino%2F102-pytorch-onnx-to-openvino.ipynb)

![segmentation result](https://user-images.githubusercontent.com/29454499/203723317-1716e3ca-b390-47e1-bb98-07b4d8d097a0.png)

The notebook uses [Model Optimizer](https://docs.openvino.ai/2023.0/openvino_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html) to convert the open-source Lite-RASPP semantic segmentation model with a MobileNet V3 Large backbone from [torchvision](https://pytorch.org/vision/main/models/lraspp.html), trained on [COCO](https://cocodataset.org) dataset images using 20 categories that are present in the [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html) dataset, to OpenVINO IR. It also shows how to do segmentation inference on an image, using [OpenVINO Runtime](https://docs.openvino.ai/nightly/openvino_docs_OV_UG_OV_Runtime_User_Guide.html) and compares the results of the PyTorch model with the OpenVINO IR model.


## Installation Instructions

If you have not installed all required dependencies, follow the [Installation Guide](../../README.md).

0 comments on commit 1e48df3

Please sign in to comment.