- [Tensorflow Pb Model Exporting](#tensorflow-pb-model-exporting)
<!-- /TOC -->
@@ -120,23 +123,41 @@ Some typical image classification networks such as ResNet and VGG have been test
> 2. The Dropout operator will be lost after conversion because the inference mode is used to load the PyTorch or TensorFlow model. Manually re-implement is necessary.
> 3. The Graph-based mode will be continuously developed and optimized with further updates.
Supported models list (Models in below table have been tested based on PyTorch 1.14.0 and TensorFlow 1.15.0, X86 Ubuntu released version):
| Supported Model | PyTorch Script | TensorFlow Script |
Supported models list (Models in below table have been tested based on PyTorch 1.4.0(TorchVision 0.5.0) and TensorFlow 1.15.0, X86 Ubuntu released version):
To use TensorFlow model script migration, you need to export TensorFlow model to Pb format first, and obtain the model input node and output node name. You can refer to the following methods to export and obtain the node name:
To use TensorFlow model script migration, users need to export TensorFlow model to Pb format first, and obtain the model input node and output node name. For exporting pb model, please refer to [TensorFlow Pb model exporting](#tensorflow-pb-model-exporting).
```python
import tensorflow as tf
from tensorflow.python.framework import graph_io
from tensorflow.keras.applications.inception_v3 import InceptionV3
After the above code is executed, the model will be saved to `/home/user/xxx/frozen_model.pb`. `INPUT_NODE` can be passed into `--input_nodes`, and `OUTPUT_NODE` is the corresponding `--output_nodes`.
Suppose the input node name is `input_1:0`, output node name is `predictions/Softmax:0`, the input shape of model is `1,224,224,3`, the following command can be used to generate the script:
Suppose the model is saved to `/home/user/xxx/frozen_model.pb`, corresponding input node name is `input_1:0`, output node name is `predictions/Softmax:0`, the input shape of model is `1,224,224,3`, the following command can be used to generate the script:
@@ -277,7 +271,7 @@ After executed MindSpore script, and report file can be found in corresponding d
The format of conversion report generated by script generation scheme based on graph structure is the same as that of AST scheme. However, since the graph based scheme is a generative method, the original pytorch script is not referenced in the conversion process. Therefore, the code line and column numbers involved in the generated conversion report refer to the generated script.
In addition, for operators that are not converted successfully, the input and output shape of tensor of the node will be identified in the code by `input_shape` and `output_shape`. For example, please refer to [PyTorch Model Scripts Conversion](#manual_modify).
In addition, for operators that are not converted successfully, the input and output shape of tensor of the node will be identified in the code by `input_shape` and `output_shape`. For example, please refer to the example in **PyTorch Model Scripts Conversion** section.
## Caution
@@ -316,6 +310,18 @@ class ConvBNReLU(nn.Sequential):
)
```
## Requirements
For users converting PyTorch model script to MindSpore, there is no need to install other third party package.
For users converting TensorFlow model script to MindSpore, in addition to install the TensorFlow can satisfy the pb model loading, inference and training, users also need to pip install the following third party package:
```text
onnx>=1.8.0
tf2onnx>=1.7.1
onnxruntime>=1.5.2
```
## Frequently asked questions
Q1. `terminate called after throwing an instance of 'std::system_error', what(): Resource temporarily unavailable, Aborted (core dumped)`:
@@ -324,3 +330,81 @@ Q1. `terminate called after throwing an instance of 'std::system_error', what():
Q2. Can MindConverter run on ARM platform?
> Answer: MindConverter usability on X86 Ubuntu machine has been verified, yet, on ARM has not.
Q3. Why did I get message of `Error detail: [NodeInputMissing] ...` when converting PyTorch model?
> Answer: For PyTorch model, if operations in `torch.nn.functional.xxx`, `torch.xxx`, `torch.Tensor.xxx` were used, node parsing could be failed. It's better to replace those operations with `torch.nn.xxx`.
## Appendix
### TensorFlow Pb model exporting
If build model with Keras API, user can try the following methods.
For TensorFlow 1.15.x version:
```python
import tensorflow as tf
from tensorflow.python.framework import graph_io
from tensorflow.python.keras.applications.inception_v3 import InceptionV3