DOCS-return ONNX and MO_techniques articles (#11805)
* DOCS-return ONNX and MO_techniques articles ONNX support article revised and changed to local tabs * Update docs/MO_DG/prepare_model/Model_Optimization_Techniques.md Co-authored-by: Yuan Xu <yuan1.xu@intel.com> * Update docs/OV_Runtime_UG/ONNX_Support.md * Update docs/OV_Runtime_UG/ONNX_Support.md * Update docs/OV_Runtime_UG/ONNX_Support.md Co-authored-by: Yuan Xu <yuan1.xu@intel.com>
This commit is contained in:
1 parent
e1bcfeca9d
commit
f635621aab
4 files changed
+134
No files matched your search
@@ -9,6 +9,7 @@
|
||||
:hidden:
|
||||
|
||||
openvino_docs_MO_DG_prepare_model_convert_model_Converting_Model
|
||||
openvino_docs_MO_DG_prepare_model_Model_Optimization_Techniques
|
||||
openvino_docs_MO_DG_prepare_model_convert_model_Cutting_Model
|
||||
openvino_docs_MO_DG_Additional_Optimization_Use_Cases
|
||||
openvino_docs_MO_DG_FP16_Compression
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# Model Optimization Techniques {#openvino_docs_MO_DG_prepare_model_Model_Optimization_Techniques}
|
||||
|
||||
Optimization offers methods to accelerate inference with the convolution neural networks (CNN) that do not require model retraining.
|
||||
|
||||
* * *
|
||||
|
||||
## Linear Operations Fusing
|
||||
|
||||
Many convolution neural networks includes `BatchNormalization` and `ScaleShift` layers (for example, Resnet\*, Inception\*) that can be presented as a sequence of linear operations: additions and multiplications. For example ScaleShift layer can be presented as Mul → Add sequence. These layers can be fused into previous `Convolution` or `FullyConnected` layers, except when Convolution comes after an Add operation (due to Convolution paddings).
|
||||
|
||||
### Usage
|
||||
|
||||
In the Model Optimizer, this optimization is turned on by default. To disable it, you can pass `--disable_fusing` parameter to the Model Optimizer.
|
||||
|
||||
### Optimization Description
|
||||
|
||||
This optimization method consists of three stages:
|
||||
|
||||
1. `BatchNormalization` and `ScaleShift` decomposition: in this stage, `BatchNormalization` layer is decomposed to `Mul → Add → Mul → Add` sequence, and `ScaleShift` layer is decomposed to `Mul → Add` layers sequence.
|
||||
|
||||
2. Linear operations merge: in this stage, the `Mul` and `Add` operations are merged into a single `Mul → Add` instance.
|
||||
For example, if there is a `BatchNormalization → ScaleShift` sequence in the topology, it is replaced with `Mul → Add` in the first stage. In the next stage, the latter is replaced with a `ScaleShift` layer if there is no available `Convolution` or `FullyConnected` layer to fuse into next.
|
||||
3. Linear operations fusion: in this stage, the tool fuses `Mul` and `Add` operations to `Convolution` or `FullyConnected` layers. Note that it searches for `Convolution` and `FullyConnected` layers both backward and forward in the graph (except for `Add` operation that cannot be fused to `Convolution` layer in forward direction).
|
||||
|
||||
### Usage Examples
|
||||
|
||||
The picture below shows the depicted part of Caffe Resnet269 topology where `BatchNorm` and `ScaleShift` layers will be fused to `Convolution` layers.
|
||||
|
||||

|
||||
|
||||
* * *
|
||||
|
||||
## ResNet optimization (stride optimization)
|
||||
|
||||
ResNet optimization is a specific optimization that applies to Caffe ResNet topologies such as ResNet50, ResNet101, ResNet152 and to ResNet-based topologies. This optimization is turned on by default, and can be disabled with the `--disable_resnet_optimization` key.
|
||||
|
||||
### Optimization Description
|
||||
|
||||
In the picture below, you can see the original and optimized parts of a Caffe ResNet50 model. The main idea of this optimization is to move the stride that is greater than 1 from Convolution layers with the kernel size = 1 to upper Convolution layers. In addition, the Model Optimizer adds a Pooling layer to align the input shape for a Eltwise layer, if it was changed during the optimization.
|
||||
|
||||

|
||||
|
||||
In this example, the stride from the `res3a_branch1` and `res3a_branch2a` Convolution layers moves to the `res2c_branch2b` Convolution layer. In addition, to align the input shape for `res2c` Eltwise, the optimization inserts the Pooling layer with kernel size = 1 and stride = 2.
|
||||
|
||||
* * *
|
||||
|
||||
## Grouped Convolution Fusing
|
||||
|
||||
Grouped convolution fusing is a specific optimization that applies for TensorFlow topologies. The main idea of this optimization is to combine convolutions results for the `Split` outputs and then recombine them using `Concat` operation in the same order as they were out from `Split`.
|
||||
|
||||

|
||||
|
||||
* * *
|
||||
|
||||
## Disabling Fusing
|
||||
|
||||
Model Optimizer allows to disable optimizations for specified nodes via `--finegrain_fusing <node_name1>,<node_name2>,...` (regex is also supported). Using this key, you mark nodes that will noy be touched by any optimizations.
|
||||
|
||||
### Examples of usage
|
||||
|
||||
On the picture below you can see two visualized Intermediate Representations (IR) of TensorFlow InceptionV4 topology.
|
||||
The first one is original IR that will be produced by the Model Optimizer.
|
||||
The second one will be produced by the Model Optimizer with key `--finegrain_fusing InceptionV4/InceptionV4/Conv2d_1a_3x3/Conv2D`, where you can see that `Convolution` was not fused with `Mul1_3752` and `Mul1_4061/Fused_Mul_5096/FusedScaleShift_5987` operations.
|
||||
|
||||

|
||||
@@ -0,0 +1,67 @@
|
||||
# ONNX Format Support {#ONNX_Format_Support}
|
||||
|
||||
|
||||
Since the 2020.4 release, OpenVINO™ has supported native usage of ONNX models. The `core.read_model()` method, which is the recommended approach to reading models, provides a uniform way to work with OpenVINO IR and ONNX formats alike. Example:
|
||||
|
||||
@sphinxdirective
|
||||
.. tab:: C++
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
ov::Core core;
|
||||
std::shared_ptr<ov::Model> model = core.read_model("model.xml")
|
||||
|
||||
.. tab:: Python
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import openvino.runtime as ov
|
||||
core = ov.Core()
|
||||
model = core.read_model("model.xml")
|
||||
@endsphinxdirective
|
||||
|
||||
While ONNX models are directly supported by OpenVINO™, it can be useful to convert them to IR format to take advantage of advanced OpenVINO optimization tools and features. For information on how to convert an ONNX model to the OpenVINO IR format, see the [Converting an ONNX Model](https://github.com/openvinotoolkit/openvino/pull/MO_DG/prepare_model/convert_model/Convert_Model_From_ONNX.md) page.
|
||||
|
||||
### Reshape Feature
|
||||
OpenVINO™ does not provide a mechanism to specify pre-processing for the ONNX format, like mean value subtraction or reverse input channels. If an ONNX model contains dynamic shapes for input, please see the [Changing input shapes](ShapeInference.md) documentation.
|
||||
|
||||
### Weights Saved in External Files
|
||||
OpenVINO™ supports ONNX models that store weights in external files. It is especially useful for models larger than 2GB because of protobuf limitations. To read such models:
|
||||
|
||||
@sphinxdirective
|
||||
.. tab:: C++
|
||||
|
||||
* Use the `read_model` overload that takes `modelPath` as the input parameter (both `std::string` and `std::wstring`).
|
||||
* The `binPath` argument of `read_model` should be empty. Otherwise, a runtime exception is thrown because paths to external weights are saved directly in the ONNX model.
|
||||
* Reading models with external weights is **NOT** supported by the `read_model()` overload.
|
||||
|
||||
.. tab:: Python
|
||||
|
||||
* Use the `model` parameter in the `openvino.runtime.Core.read_model(model : "path_to_onnx_file")` method.
|
||||
* The `weights` parameter, for the path to the binary weight file, should be empty. Otherwise, a runtime exception is thrown because paths to external weights are saved directly in the ONNX model.
|
||||
* Reading models with external weights is **NOT** supported by the `read_model(weights: "path_to_bin_file")` parameter.
|
||||
|
||||
@endsphinxdirective
|
||||
|
||||
Paths to external weight files are saved in an ONNX model. They are relative to the model's directory path, which means that for a model located at `workspace/models/model.onnx` and a weights file at `workspace/models/data/weights.bin`, the path saved in the model would be: `data/weights.bin`.
|
||||
|
||||
Note that a single model can use many external weights files.
|
||||
What is more, data of many tensors can be stored in a single external weights file, processed using offset and length values, which can also be saved in a model.
|
||||
|
||||
The following input parameters are NOT supported for ONNX models and should be passed as empty (none) or not at all:
|
||||
|
||||
* for `ReadNetwork` (C++):
|
||||
* `const std::wstring& binPath`
|
||||
* `const std::string& binPath`
|
||||
* `const Tensor& weights`
|
||||
* for [openvino.runtime.Core.read_model](https://docs.openvino.ai/latest/api/ie_python_api/_autosummary/openvino.runtime.Core.html#openvino.runtime.Core.read_model)
|
||||
* `weights`
|
||||
|
||||
|
||||
You can find more details about the external data mechanism in [ONNX documentation](https://github.com/onnx/onnx/blob/master/docs/ExternalData.md).
|
||||
To convert a model to use the external data feature, you can use [ONNX helper functions](https://github.com/onnx/onnx/blob/master/onnx/external_data_helper.py).
|
||||
|
||||
Unsupported types of tensors:
|
||||
* string
|
||||
* complex64
|
||||
* complex128
|
||||
@@ -19,6 +19,7 @@
|
||||
openvino_docs_OV_UG_Performance_Hints
|
||||
openvino_docs_OV_UG_Automatic_Batching
|
||||
openvino_docs_OV_UG_network_state_intro
|
||||
ONNX_Format_Support
|
||||
|
||||
@endsphinxdirective
|
||||
|
||||
|
||||
Reference in new issue
Block a user