Skip to content

Commit

Permalink
[DOCS] Fixing formatting issues in articles (openvinotoolkit#17994)
Browse files Browse the repository at this point in the history
* fixing-formatting
  • Loading branch information
sgolebiewski-intel authored and alvoron committed Jun 21, 2023
1 parent 6e8fa60 commit e9e430e
Show file tree
Hide file tree
Showing 20 changed files with 293 additions and 306 deletions.
2 changes: 1 addition & 1 deletion docs/Documentation/inference_modes_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ OpenVINO Runtime offers multiple inference modes to allow optimum hardware utili
The remaining modes assume certain levels of automation in selecting devices for inference. Using them in the deployed solution may potentially increase its performance and portability. The automated modes are:

* :doc:`Automatic Device Selection (AUTO) <openvino_docs_OV_UG_supported_plugins_AUTO>`
* :doc:``Multi-Device Execution (MULTI) <openvino_docs_OV_UG_Running_on_multiple_devices>`
* :doc:`Multi-Device Execution (MULTI) <openvino_docs_OV_UG_Running_on_multiple_devices>`
* :doc:`Heterogeneous Execution (HETERO) <openvino_docs_OV_UG_Hetero_execution>`
* :doc:`Automatic Batching Execution (Auto-batching) <openvino_docs_OV_UG_Automatic_Batching>`

Expand Down
34 changes: 17 additions & 17 deletions docs/MO_DG/prepare_model/convert_model/Convert_Model_From_Kaldi.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

Note that OpenVINO support for Kaldi is currently being deprecated and will be removed entirely in the future.

.. note::
.. note::

Model conversion API supports the `nnet1 <http://kaldi-asr.org/doc/dnn1.html>`__ and `nnet2 <http://kaldi-asr.org/doc/dnn2.html>`__ formats of Kaldi models. The support of the `nnet3 <http://kaldi-asr.org/doc/dnn3.html>`__ format is limited.

To convert a Kaldi model, run model conversion with the path to the input model ``.nnet`` or ``.mdl`` file:

.. code-block:: cpp

mo --input_model <INPUT_MODEL>.nnet

Using Kaldi-Specific Conversion Parameters
Using Kaldi-Specific Conversion Parameters
##########################################

The following list provides the Kaldi-specific parameters.
Expand All @@ -34,43 +34,43 @@ Examples of CLI Commands
########################

* To launch model conversion for the ``wsj_dnn5b_smbr`` model with the specified ``.nnet`` file:

.. code-block:: cpp

mo --input_model wsj_dnn5b_smbr.nnet

* To launch model conversion for the ``wsj_dnn5b_smbr`` model with the existing file that contains counts for the last layer with biases:

.. code-block:: cpp

mo --input_model wsj_dnn5b_smbr.nnet --counts wsj_dnn5b_smbr.counts


* The model conversion normalizes сounts in the following way:

.. math::

S = \frac{1}{\sum_{j = 0}^{|C|}C_{j}}

.. math::

C_{i}=log(S\*C_{i})
where :math:`C` - the counts array, :math:`C_{i} - i^{th}` element of the counts array, :math:`|C|` - number of elements in the counts array;

where :math:`C` - the counts array, :math:`C_{i} - i^{th}` element of the counts array, :math:`|C|` - number of elements in the counts array;

* The normalized counts are subtracted from biases of the last or next to last layer (if last layer is SoftMax).

.. note:: Model conversion API will show a warning if a model contains values of counts and the ``counts`` option is not used.

* If you want to remove the last SoftMax layer in the topology, launch the model conversion with the ``remove_output_softmax`` flag:

.. code-block:: cpp
.. code-block:: cpp

mo --input_model wsj_dnn5b_smbr.nnet --counts wsj_dnn5b_smbr.counts --remove_output_softmax
mo --input_model wsj_dnn5b_smbr.nnet --counts wsj_dnn5b_smbr.counts --remove_output_softmax

Model conversion API finds the last layer of the topology and removes this layer only if it is a SoftMax layer.
Model conversion API finds the last layer of the topology and removes this layer only if it is a SoftMax layer.

.. note:: Model conversion can remove SoftMax layer only if the topology has one output.
.. note:: Model conversion can remove SoftMax layer only if the topology has one output.

* You can use the *OpenVINO Speech Recognition* sample application for the sample inference of Kaldi models. This sample supports models with only one output. If your model has several outputs, specify the desired one with the ``output`` option.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This page provides general instructions on how to run model conversion from a Te

To use model conversion API, install OpenVINO Development Tools by following the :doc:`installation instructions <openvino_docs_install_guides_install_dev_tools>`.

Converting TensorFlow 1 Models
Converting TensorFlow 1 Models
###############################

Converting Frozen Model Format
Converting Frozen Model Format
+++++++++++++++++++++++++++++++

To convert a TensorFlow model, use the ``*mo*`` script to simply convert a model with a path to the input model ``*.pb*`` file:
Expand All @@ -19,7 +19,7 @@ To convert a TensorFlow model, use the ``*mo*`` script to simply convert a model
mo --input_model <INPUT_MODEL>.pb


Converting Non-Frozen Model Formats
Converting Non-Frozen Model Formats
+++++++++++++++++++++++++++++++++++

There are three ways to store non-frozen TensorFlow models and convert them by model conversion API:
Expand Down Expand Up @@ -62,14 +62,14 @@ If a model contains operations currently unsupported by OpenVINO, prune these op
To determine custom input nodes, display a graph of the model in TensorBoard. To generate TensorBoard logs of the graph, use the ``--tensorboard_logs`` option.
TensorFlow 2.x SavedModel format has a specific graph due to eager execution. In case of pruning, find custom input nodes in the ``StatefulPartitionedCall/*`` subgraph of TensorFlow 2.x SavedModel format.

Freezing Custom Models in Python
Freezing Custom Models in Python
++++++++++++++++++++++++++++++++

When a network is defined in Python code, you have to create an inference graph file. Graphs are usually built in a form
that allows model training. That means all trainable parameters are represented as variables in the graph.
To be able to use such graph with model conversion API, it should be frozen and dumped to a file with the following code:

.. code-block:: python
.. code-block:: python

import tensorflow as tf
from tensorflow.python.framework import graph_io
Expand All @@ -84,7 +84,7 @@ Where:
* ``inference_graph.pb`` is the name of the generated inference graph file.
* ``as_text`` specifies whether the generated file should be in human readable text format or binary.

Converting TensorFlow 2 Models
Converting TensorFlow 2 Models
###############################

To convert TensorFlow 2 models, ensure that `openvino-dev[tensorflow2]` is installed via `pip`.
Expand Down Expand Up @@ -114,7 +114,7 @@ pruning, find custom input nodes in the ``StatefulPartitionedCall/*`` subgraph.
Since the 2023.0 release, direct pruning of models in SavedModel format is not supported.
It is essential to freeze the model before pruning. Use the following code snippet for model freezing:

.. code-block:: python
.. code-block:: python

import tensorflow as tf
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
Expand Down Expand Up @@ -155,7 +155,7 @@ For example, the model with a custom layer ``CustomLayer`` from ``custom_layer.p

Then follow the above instructions for the SavedModel format.

.. note::
.. note::

Do not use other hacks to resave TensorFlow 2 models into TensorFlow 1 formats.

Expand All @@ -164,23 +164,23 @@ Command-Line Interface (CLI) Examples Using TensorFlow-Specific Parameters

* Launching model conversion for Inception V1 frozen model when model file is a plain text protobuf:

.. code-block:: sh
.. code-block:: sh

mo --input_model inception_v1.pbtxt --input_model_is_text -b 1
mo --input_model inception_v1.pbtxt --input_model_is_text -b 1


* Launching model conversion for Inception V1 frozen model and dump information about the graph to TensorBoard log dir ``/tmp/log_dir``

.. code-block:: sh
.. code-block:: sh

mo --input_model inception_v1.pb -b 1 --tensorboard_logdir /tmp/log_dir
mo --input_model inception_v1.pb -b 1 --tensorboard_logdir /tmp/log_dir


* Launching model conversion for BERT model in the SavedModel format, with three inputs. Specify explicitly the input shapes where the batch size and the sequence length equal 2 and 30 respectively.

.. code-block:: sh
.. code-block:: sh

mo --saved_model_dir BERT --input mask,word_ids,type_ids --input_shape [2,30],[2,30],[2,30]
mo --saved_model_dir BERT --input mask,word_ids,type_ids --input_shape [2,30],[2,30],[2,30]

Conversion of TensorFlow models from memory using Python API
############################################################
Expand All @@ -189,96 +189,96 @@ Model conversion API supports passing TensorFlow/TensorFlow2 models directly fro

* ``tf.keras.Model``

.. code-block:: python
.. code-block:: python

model = tf.keras.applications.ResNet50(weights="imagenet")
ov_model = convert_model(model)
model = tf.keras.applications.ResNet50(weights="imagenet")
ov_model = convert_model(model)


* ``tf.keras.layers.Layer``. Requires setting the "input_shape".

.. code-block:: python
.. code-block:: python

import tensorflow_hub as hub
import tensorflow_hub as hub

model = hub.KerasLayer("https://tfhub.dev/google/imagenet/mobilenet_v1_100_224/classification/5")
ov_model = convert_model(model, input_shape=[-1, 224, 224, 3])
model = hub.KerasLayer("https://tfhub.dev/google/imagenet/mobilenet_v1_100_224/classification/5")
ov_model = convert_model(model, input_shape=[-1, 224, 224, 3])

* ``tf.Module``. Requires setting the "input_shape".

.. code-block:: python
.. code-block:: python

class MyModule(tf.Module):
def __init__(self, name=None):
super().__init__(name=name)
self.variable1 = tf.Variable(5.0, name="var1")
self.variable2 = tf.Variable(1.0, name="var2")
def __call__(self, x):
return self.variable1 * x + self.variable2
class MyModule(tf.Module):
def __init__(self, name=None):
super().__init__(name=name)
self.variable1 = tf.Variable(5.0, name="var1")
self.variable2 = tf.Variable(1.0, name="var2")
def __call__(self, x):
return self.variable1 * x + self.variable2

model = MyModule(name="simple_module")
ov_model = convert_model(model, input_shape=[-1])
model = MyModule(name="simple_module")
ov_model = convert_model(model, input_shape=[-1])

* ``tf.compat.v1.Graph``

.. code-block:: python
.. code-block:: python

with tf.compat.v1.Session() as sess:
inp1 = tf.compat.v1.placeholder(tf.float32, [100], 'Input1')
inp2 = tf.compat.v1.placeholder(tf.float32, [100], 'Input2')
output = tf.nn.relu(inp1 + inp2, name='Relu')
tf.compat.v1.global_variables_initializer()
model = sess.graph

with tf.compat.v1.Session() as sess:
inp1 = tf.compat.v1.placeholder(tf.float32, [100], 'Input1')
inp2 = tf.compat.v1.placeholder(tf.float32, [100], 'Input2')
output = tf.nn.relu(inp1 + inp2, name='Relu')
tf.compat.v1.global_variables_initializer()
model = sess.graph

ov_model = convert_model(model)
ov_model = convert_model(model)

* ``tf.compat.v1.GraphDef``

.. code-block:: python
.. code-block:: python

with tf.compat.v1.Session() as sess:
inp1 = tf.compat.v1.placeholder(tf.float32, [100], 'Input1')
inp2 = tf.compat.v1.placeholder(tf.float32, [100], 'Input2')
output = tf.nn.relu(inp1 + inp2, name='Relu')
tf.compat.v1.global_variables_initializer()
model = sess.graph_def

with tf.compat.v1.Session() as sess:
inp1 = tf.compat.v1.placeholder(tf.float32, [100], 'Input1')
inp2 = tf.compat.v1.placeholder(tf.float32, [100], 'Input2')
output = tf.nn.relu(inp1 + inp2, name='Relu')
tf.compat.v1.global_variables_initializer()
model = sess.graph_def

ov_model = convert_model(model)
ov_model = convert_model(model)

* ``tf.function``

.. code-block:: python
.. code-block:: python

@tf.function(
input_signature=[tf.TensorSpec(shape=[1, 2, 3], dtype=tf.float32),
tf.TensorSpec(shape=[1, 2, 3], dtype=tf.float32)])
def func(x, y):
return tf.nn.sigmoid(tf.nn.relu(x + y))

@tf.function(
input_signature=[tf.TensorSpec(shape=[1, 2, 3], dtype=tf.float32),
tf.TensorSpec(shape=[1, 2, 3], dtype=tf.float32)])
def func(x, y):
return tf.nn.sigmoid(tf.nn.relu(x + y))

ov_model = convert_model(func)
ov_model = convert_model(func)

* ``tf.compat.v1.session``

.. code-block:: python
.. code-block:: python

with tf.compat.v1.Session() as sess:
inp1 = tf.compat.v1.placeholder(tf.float32, [100], 'Input1')
inp2 = tf.compat.v1.placeholder(tf.float32, [100], 'Input2')
output = tf.nn.relu(inp1 + inp2, name='Relu')
tf.compat.v1.global_variables_initializer()
with tf.compat.v1.Session() as sess:
inp1 = tf.compat.v1.placeholder(tf.float32, [100], 'Input1')
inp2 = tf.compat.v1.placeholder(tf.float32, [100], 'Input2')
output = tf.nn.relu(inp1 + inp2, name='Relu')
tf.compat.v1.global_variables_initializer()

ov_model = convert_model(sess)
ov_model = convert_model(sess)

* ``tf.train.checkpoint``

.. code-block:: python
.. code-block:: python

model = tf.keras.Model(...)
checkpoint = tf.train.Checkpoint(model)
save_path = checkpoint.save(save_directory)
# ...
checkpoint.restore(save_path)
ov_model = convert_model(checkpoint)
model = tf.keras.Model(...)
checkpoint = tf.train.Checkpoint(model)
save_path = checkpoint.save(save_directory)
# ...
checkpoint.restore(save_path)
ov_model = convert_model(checkpoint)

Supported TensorFlow and TensorFlow 2 Keras Layers
##################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ This article provides the instructions and examples on how to convert `GluonCV S

2. Run model conversion API, specifying the ``enable_ssd_gluoncv`` option. Make sure the ``input_shape`` parameter is set to the input shape layout of your model (NHWC or NCHW). The examples below illustrate running model conversion for the SSD and YOLO-v3 models trained with the NHWC layout and located in the ``<model_directory>``:

* **For GluonCV SSD topologies:**
* **For GluonCV SSD topologies:**

.. code-block:: sh
.. code-block:: sh

mo --input_model <model_directory>/ssd_512_mobilenet1.0.params --enable_ssd_gluoncv --input_shape [1,512,512,3] --input data --output_dir <OUTPUT_MODEL_DIR>
mo --input_model <model_directory>/ssd_512_mobilenet1.0.params --enable_ssd_gluoncv --input_shape [1,512,512,3] --input data --output_dir <OUTPUT_MODEL_DIR>

* **For YOLO-v3 topology:**
* **For YOLO-v3 topology:**

* To convert the model:
* To convert the model:

.. code-block:: sh
.. code-block:: sh

mo --input_model <model_directory>/yolo3_mobilenet1.0_voc-0000.params --input_shape [1,255,255,3] --output_dir <OUTPUT_MODEL_DIR>
mo --input_model <model_directory>/yolo3_mobilenet1.0_voc-0000.params --input_shape [1,255,255,3] --output_dir <OUTPUT_MODEL_DIR>

* To convert the model with replacing the subgraph with RegionYolo layers:
* To convert the model with replacing the subgraph with RegionYolo layers:

.. code-block:: sh
.. code-block:: sh

mo --input_model <model_directory>/models/yolo3_mobilenet1.0_voc-0000.params --input_shape [1,255,255,3] --transformations_config "front/mxnet/yolo_v3_mobilenet1_voc. json" --output_dir <OUTPUT_MODEL_DIR>
mo --input_model <model_directory>/models/yolo3_mobilenet1.0_voc-0000.params --input_shape [1,255,255,3] --transformations_config "front/mxnet/ yolo_v3_mobilenet1_voc. json" --output_dir <OUTPUT_MODEL_DIR>


@endsphinxdirective
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Converting a YOLACT Model to the OpenVINO IR format
mo --input_model /path/to/yolact.onnx


**Step 4**. Embed input preprocessing into the IR:
**Step 5**. Embed input preprocessing into the IR:

To get performance gain by offloading to the OpenVINO application of mean/scale values and RGB->BGR conversion, use the following model conversion API parameters:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ Follow these steps to make a pretrained TensorFlow BERT model reshapable over ba

* For UNIX-like systems, run the following command:

.. code-block:: sh
.. code-block:: sh

wget https://gist.githubusercontent.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e/raw/17b8dd0d724281ed7c3b2aeeda662b92809aadd5/download_glue_data.py
wget https://gist.githubusercontent.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e/raw/17b8dd0d724281ed7c3b2aeeda662b92809aadd5/download_glue_data.py

* For Windows systems:

Download the `Python script <https://gist.githubusercontent.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e/raw/17b8dd0d724281ed7c3b2aeeda662b92809aadd5/download_glue_data.py>`__ to the current working directory.
Download the `Python script <https://gist.githubusercontent.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e/raw/17b8dd0d724281ed7c3b2aeeda662b92809aadd5/download_glue_data.py>`__ to the current working directory.

6. Download GLUE data by running:

Expand Down
Loading

0 comments on commit e9e430e

Please sign in to comment.