Skip to content

Commit 7f51f99

Browse files
committed
Merge remote-tracking branch 'up/master' into revise_swish
2 parents 63c2e3e + 4dc9c03 commit 7f51f99

File tree

43 files changed

+1223
-539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1223
-539
lines changed

docs/IE_DG/Migration_CoreAPI.md

-70
This file was deleted.

docs/IE_DG/OnnxImporterTutorial.md

-67
This file was deleted.

docs/IE_DG/supported_plugins/FPGA.md

-22
This file was deleted.

docs/MO_DG/img/DeepSpeech-0.8.2.png

+3
Loading

docs/MO_DG/img/DeepSpeech.png

-3
This file was deleted.

docs/MO_DG/prepare_model/convert_model/Convert_Model_From_TensorFlow.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Where `HEIGHT` and `WIDTH` are the input images height and width for which the m
161161
* [GNMT](https://github.com/tensorflow/nmt) topology can be converted using [these instructions](tf_specific/Convert_GNMT_From_Tensorflow.md).
162162
* [BERT](https://github.com/google-research/bert) topology can be converted using [these instructions](tf_specific/Convert_BERT_From_Tensorflow.md).
163163
* [XLNet](https://github.com/zihangdai/xlnet) topology can be converted using [these instructions](tf_specific/Convert_XLNet_From_Tensorflow.md).
164-
164+
* [Attention OCR](https://github.com/emedvedev/attention-ocr) topology can be converted using [these instructions](tf_specific/Convert_AttentionOCR_From_Tensorflow.md).
165165

166166

167167
## Loading Non-Frozen Models to the Model Optimizer <a name="loading-nonfrozen-models"></a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Convert TensorFlow* Attention OCR Model to Intermediate Representation {#openvino_docs_MO_DG_prepare_model_convert_model_tf_specific_Convert_AttentionOCR_From_Tensorflow}
2+
3+
This tutorial explains how to convert the Attention OCR (AOCR) model from the [TensorFlow* Attention OCR repository](https://github.com/emedvedev/attention-ocr) to the Intermediate Representation (IR).
4+
5+
## Extract Model from `aocr` Library
6+
7+
The easiest way to get an AOCR model is to download `aocr` Python\* library:
8+
```
9+
pip install git+https://github.com/emedvedev/attention-ocr.git@master#egg=aocr
10+
```
11+
This library contains a pretrained model and allows to train and run AOCR using the command line. After installing `aocr`, you can extract the model:
12+
```
13+
aocr export --format=frozengraph model/path/
14+
```
15+
After this step you can find the model in model/path/ folder.
16+
17+
## Convert the TensorFlow* AOCR Model to IR
18+
19+
The original AOCR model contains data preprocessing which consists of the following steps:
20+
* Decoding input data to binary format where input data is an image represented as a string.
21+
* Resizing binary image to working resolution.
22+
23+
After that, the resized image is sent to the convolution neural network (CNN). The Model Optimizer does not support image decoding so you should cut of preprocessing part of the model using '--input' command line parameter.
24+
```sh
25+
python3 path/to/model_optimizer/mo_tf.py \
26+
--input_model=model/path/frozen_graph.pb \
27+
--input="map/TensorArrayStack/TensorArrayGatherV3:0[1 32 86 1]" \
28+
--output "transpose_1,transpose_2" \
29+
--output_dir path/to/ir/
30+
```
31+
32+
Where:
33+
* `map/TensorArrayStack/TensorArrayGatherV3:0[1 32 86 1]` - name of node producing tensor after preprocessing.
34+
* `transpose_1` - name of the node producing tensor with predicted characters.
35+
* `transpose_2` - name of the node producing tensor with predicted characters probabilties

docs/MO_DG/prepare_model/convert_model/tf_specific/Convert_DeepSpeech_From_Tensorflow.md

+52-37
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,81 @@
22

33
[DeepSpeech project](https://github.com/mozilla/DeepSpeech) provides an engine to train speech-to-text models.
44

5-
## Download the Pre-Trained DeepSpeech Model
5+
## Download the Pretrained DeepSpeech Model
66

7-
[Pre-trained English speech-to-text model](https://github.com/mozilla/DeepSpeech#getting-the-pre-trained-model)
8-
is publicly available. To download the model, please follow the instruction below:
7+
Create a directory where model and metagraph with pretrained weights will be stored:
8+
```
9+
mkdir deepspeech
10+
cd deepspeech
11+
```
12+
[Pretrained English speech-to-text model](https://github.com/mozilla/DeepSpeech/releases/tag/v0.8.2) is publicly available.
13+
To download the model, follow the instruction below:
914

1015
* For UNIX*-like systems, run the following command:
1116
```
12-
wget -O - https://github.com/mozilla/DeepSpeech/releases/download/v0.3.0/deepspeech-0.3.0-models.tar.gz | tar xvfz -
17+
wget -O - https://github.com/mozilla/DeepSpeech/archive/v0.8.2.tar.gz | tar xvfz -
18+
wget -O - https://github.com/mozilla/DeepSpeech/releases/download/v0.8.2/deepspeech-0.8.2-checkpoint.tar.gz | tar xvfz -
1319
```
1420
* For Windows* systems:
15-
1. Download the archive from the DeepSpeech project repository: [https://github.com/mozilla/DeepSpeech/releases/download/v0.3.0/deepspeech-0.3.0-models.tar.gz](https://github.com/mozilla/DeepSpeech/releases/download/v0.3.0/deepspeech-0.3.0-models.tar.gz).
16-
2. Unpack it with a file archiver application.
21+
1. Download the archive with the model: [https://github.com/mozilla/DeepSpeech/archive/v0.8.2.tar.gz](https://github.com/mozilla/DeepSpeech/archive/v0.8.2.tar.gz).
22+
2. Download the TensorFlow\* MetaGraph with pretrained weights: [https://github.com/mozilla/DeepSpeech/releases/download/v0.8.2/deepspeech-0.8.2-checkpoint.tar.gz](https://github.com/mozilla/DeepSpeech/releases/download/v0.8.2/deepspeech-0.8.2-checkpoint.tar.gz).
23+
3. Unpack it with a file archiver application.
24+
25+
## Freeze the Model into a *.pb File
1726

18-
After you unpack the archive with the pre-trained model, you will have the new `models` directory with the
19-
following files:
27+
After unpacking the archives above, you have to freeze the model. Note that this requires
28+
TensorFlow* version 1 which is not available under Python 3.8, so you need Python 3.7 or lower.
29+
Before freezing, deploy a virtual environment and install the required packages:
2030
```
21-
alphabet.txt
22-
lm.binary
23-
output_graph.pb
24-
output_graph.pbmm
25-
output_graph.rounded.pb
26-
output_graph.rounded.pbmm
27-
trie
31+
virtualenv --python=python3.7 venv-deep-speech
32+
source venv-deep-speech/bin/activate
33+
cd DeepSpeech-0.8.2
34+
pip3 install -e .
2835
```
36+
Freeze the model with the following command:
37+
```
38+
python3 DeepSpeech.py --checkpoint_dir ../deepspeech-0.8.2-checkpoint --export_dir ../
39+
```
40+
After that, you will get the pretrained frozen model file `output_graph.pb` in the directory `deepspeech` created at
41+
the beginning. The model contains the preprocessing and main parts. The first preprocessing part performs conversion of input
42+
spectrogram into a form useful for speech recognition (mel). This part of the model is not convertible into
43+
IR because it contains unsupported operations `AudioSpectrogram` and `Mfcc`.
2944

30-
Pre-trained frozen model file is `output_graph.pb`.
31-
32-
![DeepSpeech model view](../../../img/DeepSpeech.png)
45+
The main and most computationally expensive part of the model converts the preprocessed audio into text.
46+
There are two specificities with the supported part of the model.
3347

34-
As you can see, the frozen model still has two variables: `previous_state_c` and
35-
`previous_state_h`. It means that the model keeps training those variables at each inference.
48+
The first is that the model contains an input with sequence length. So the model can be converted with
49+
a fixed input length shape, thus the model is not reshapeable.
50+
Refer to the [Using Shape Inference](../../../../IE_DG/ShapeInference.md).
3651

37-
At the first inference of this graph, the variables are initialized by zero tensors. After executing the `lstm_fused_cell` nodes, cell state and hidden state, which are the results of the `BlockLSTM` execution, are assigned to these two variables.
52+
The second is that the frozen model still has two variables: `previous_state_c` and `previous_state_h`, figure
53+
with the frozen *.pb model is below. It means that the model keeps training these variables at each inference.
3854

39-
With each inference of the DeepSpeech graph, initial cell state and hidden state data for `BlockLSTM` is taken from previous inference from variables. Outputs (cell state and hidden state) of `BlockLSTM` are reassigned to the same variables.
55+
![DeepSpeech model view](../../../img/DeepSpeech-0.8.2.png)
4056

41-
It helps the model to remember the context of the words that it takes as input.
57+
At the first inference the variables are initialized with zero tensors. After executing, the results of the `BlockLSTM`
58+
are assigned to cell state and hidden state, which are these two variables.
4259

43-
## Convert the TensorFlow* DeepSpeech Model to IR
60+
## Convert the Main Part of DeepSpeech Model into IR
4461

45-
The Model Optimizer assumes that the output model is for inference only. That is why you should cut those variables off and resolve keeping cell and hidden states on the application level.
62+
Model Optimizer assumes that the output model is for inference only. That is why you should cut `previous_state_c`
63+
and `previous_state_h` variables off and resolve keeping cell and hidden states on the application level.
4664

4765
There are certain limitations for the model conversion:
4866
- Time length (`time_len`) and sequence length (`seq_len`) are equal.
4967
- Original model cannot be reshaped, so you should keep original shapes.
5068

51-
To generate the DeepSpeech Intermediate Representation (IR), provide the TensorFlow DeepSpeech model to the Model Optimizer with the following parameters:
69+
To generate the IR, run the Model Optimizer with the following parameters:
5270
```sh
53-
python3 ./mo_tf.py \
54-
--input_model path_to_model/output_graph.pb \
55-
--freeze_placeholder_with_value input_lengths->[16] \
56-
--input input_node,previous_state_h/read,previous_state_c/read \
57-
--input_shape [1,16,19,26],[1,2048],[1,2048] \
58-
--output raw_logits,lstm_fused_cell/GatherNd,lstm_fused_cell/GatherNd_1 \
71+
python3 {path_to_mo}/mo_tf.py \
72+
--input_model output_graph.pb \
73+
--input "input_lengths->[16],input_node[1 16 19 26],previous_state_h[1 2048],previous_state_c[1 2048]" \
74+
--output "cudnn_lstm/rnn/multi_rnn_cell/cell_0/cudnn_compatible_lstm_cell/GatherNd_1,cudnn_lstm/rnn/multi_rnn_cell/cell_0/cudnn_compatible_lstm_cell/GatherNd,logits" \
5975
--disable_nhwc_to_nchw
6076
```
6177

6278
Where:
63-
* `--freeze_placeholder_with_value input_lengths->[16]` freezes sequence length
64-
* `--input input_node,previous_state_h/read,previous_state_c/read` and
65-
`--input_shape [1,16,19,26],[1,2048],[1,2048]` replace the variables with a placeholder
66-
* `--output raw_logits,lstm_fused_cell/GatherNd,lstm_fused_cell/GatherNd_1` gets data for the next model
67-
execution.
79+
* `input_lengths->[16]` Replaces the input node with name "input_lengths" with a constant tensor of shape [1] with a
80+
single integer value 16. This means that the model now can consume input sequences of length 16 only.
81+
* `input_node[1 16 19 26],previous_state_h[1 2048],previous_state_c[1 2048]` replaces the variables with a placeholder.
82+
* `--output ".../GatherNd_1,.../GatherNd,logits" ` output node names.

docs/doxygen/doxygen-ignore.txt

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ inference-engine/include/vpu/vpu_config.hpp
2222
inference-engine/include/vpu/vpu_plugin_config.hpp
2323
openvino/docs/benchmarks/performance_int8_vs_fp32.md
2424
openvino/docs/get_started/get_started_macos.md
25+
openvino/docs/optimization_guide/dldt_optimization_guide.md
26+
openvino/docs/IE_DG/ShapeInference.md
2527
inference-engine/include/details/ie_so_pointer.hpp
2628
inference-engine/include/ie_compound_blob.h
2729
inference-engine/include/ie_data.h

0 commit comments

Comments
 (0)