Update tflite_convert documentation
PiperOrigin-RevId: 342789298 Change-Id: I83e9a8e356b894a509ad13b4b496f1e7a11e91eb
This commit is contained in:
parent
1182e16f88
commit
10bad81944
@ -236,53 +236,10 @@ function tends to get fused).
|
||||
|
||||
## Visualization <a name="visualization"></a>
|
||||
|
||||
The converter can export a model to the Graphviz Dot format for easy
|
||||
visualization using either the `--output_format` flag or the
|
||||
`--dump_graphviz_dir` flag. The subsections below outline the use cases for
|
||||
each.
|
||||
|
||||
### Using `--output_format=GRAPHVIZ_DOT` <a name="using_output_format_graphviz_dot"></a>
|
||||
|
||||
The first way to get a Graphviz rendering is to pass `GRAPHVIZ_DOT` into
|
||||
`--output_format`. This results in a plausible visualization of the model. This
|
||||
reduces the requirements that exist during conversion from a TensorFlow GraphDef
|
||||
to a TensorFlow Lite model. This may be useful if the conversion to TFLite is
|
||||
failing.
|
||||
|
||||
```
|
||||
tflite_convert \
|
||||
--graph_def_file=/tmp/mobilenet_v1_0.50_128/frozen_graph.pb \
|
||||
--output_file=/tmp/foo.dot \
|
||||
--output_format=GRAPHVIZ_DOT \
|
||||
--input_arrays=input \
|
||||
--input_shape=1,128,128,3 \
|
||||
--output_arrays=MobilenetV1/Predictions/Reshape_1
|
||||
|
||||
```
|
||||
|
||||
The resulting `.dot` file can be rendered into a PDF as follows:
|
||||
|
||||
```
|
||||
dot -Tpdf -O /tmp/foo.dot
|
||||
```
|
||||
|
||||
And the resulting `.dot.pdf` can be viewed in any PDF viewer, but we suggest one
|
||||
with a good ability to pan and zoom across a very large page. Google Chrome does
|
||||
well in that respect.
|
||||
|
||||
```
|
||||
google-chrome /tmp/foo.dot.pdf
|
||||
```
|
||||
|
||||
Example PDF files are viewable online in the next section.
|
||||
|
||||
### Using `--dump_graphviz_dir`
|
||||
|
||||
The second way to get a Graphviz rendering is to pass the `--dump_graphviz_dir`
|
||||
flag, specifying a destination directory to dump Graphviz rendering to. Unlike
|
||||
the previous approach, this one retains the original output format. This
|
||||
provides a visualization of the actual model resulting from a specific
|
||||
conversion process.
|
||||
The first way to get a Graphviz rendering is to pass the `--dump_graphviz_dir`
|
||||
flag, specifying a destination directory to dump Graphviz rendering to.
|
||||
|
||||
```
|
||||
tflite_convert \
|
||||
@ -295,19 +252,28 @@ tflite_convert \
|
||||
|
||||
This generates a few files in the destination directory. The two most important
|
||||
files are `toco_AT_IMPORT.dot` and `/tmp/toco_AFTER_TRANSFORMATIONS.dot`.
|
||||
`toco_AT_IMPORT.dot` represents the original model containing only the
|
||||
transformations done at import time. This tends to be a complex visualization
|
||||
with limited information about each node. It is useful in situations where a
|
||||
conversion command fails.
|
||||
|
||||
`toco_AFTER_TRANSFORMATIONS.dot` represents the model after all transformations
|
||||
were applied to it, just before it is exported. Typically, this is a much
|
||||
smaller model with more information about each node.
|
||||
- `toco_AT_IMPORT.dot` represents the original model containing only the
|
||||
transformations done at import time. This tends to be a complex
|
||||
visualization with limited information about each node. It is useful in
|
||||
situations where a conversion command fails.
|
||||
|
||||
As before, these can be rendered to PDFs:
|
||||
- `toco_AFTER_TRANSFORMATIONS.dot` represents the model after all
|
||||
transformations were applied to it, just before it is exported. Typically,
|
||||
this is a much smaller model with more information about each node.
|
||||
|
||||
These can be rendered to PDFs:
|
||||
|
||||
```
|
||||
dot -Tpdf -O /tmp/toco_*.dot
|
||||
dot -Tpdf /tmp/toco_*.dot -O
|
||||
```
|
||||
|
||||
And the resulting `.dot.pdf` can be viewed in any PDF viewer, but we suggest one
|
||||
with a good ability to pan and zoom across a very large page. Google Chrome does
|
||||
well in that respect.
|
||||
|
||||
```
|
||||
google-chrome /tmp/foo.dot.pdf
|
||||
```
|
||||
|
||||
Sample output files can be seen here below. Note that it is the same
|
||||
@ -328,6 +294,46 @@ Sample output files can be seen here below. Note that it is the same
|
||||
<tr><td>before</td><td>after</td></tr>
|
||||
</table>
|
||||
|
||||
### Using `--output_format=GRAPHVIZ_DOT` <a name="using_output_format_graphviz_dot"></a>
|
||||
|
||||
*Note: This only works when you set flag `experimental_new_converter=False`.
|
||||
Also, as this format leads to loss of TFLite specific transformations, we
|
||||
recommend that you use `--dump_graphviz_dir` instead to get a final
|
||||
visualization with all graph transformations.*
|
||||
|
||||
The second way to get a Graphviz rendering is to pass `GRAPHVIZ_DOT` into
|
||||
`--output_format`. This results in a plausible visualization of the model. This
|
||||
reduces the requirements that exist during conversion from a TensorFlow GraphDef
|
||||
to a TensorFlow Lite model. This may be useful if the conversion to TFLite is
|
||||
failing.
|
||||
|
||||
```
|
||||
tflite_convert \
|
||||
--experimental_new_converter=False
|
||||
--graph_def_file=/tmp/mobilenet_v1_0.50_128/frozen_graph.pb \
|
||||
--output_format=GRAPHVIZ_DOT \
|
||||
--output_file=/tmp/foo.dot \
|
||||
--output_format=GRAPHVIZ_DOT \
|
||||
--input_arrays=input \
|
||||
--input_shape=1,128,128,3 \
|
||||
--output_arrays=MobilenetV1/Predictions/Reshape_1
|
||||
|
||||
```
|
||||
|
||||
The resulting `.dot` file can be rendered into a PDF as follows:
|
||||
|
||||
```
|
||||
dot -Tpdf /tmp/foo.dot -O
|
||||
```
|
||||
|
||||
And the resulting `.dot.pdf` can be viewed in any PDF viewer, but we suggest one
|
||||
with a good ability to pan and zoom across a very large page. Google Chrome does
|
||||
well in that respect.
|
||||
|
||||
```
|
||||
google-chrome /tmp/foo.dot.pdf
|
||||
```
|
||||
|
||||
### Video logging
|
||||
|
||||
When `--dump_graphviz_dir` is used, one may additionally pass
|
||||
|
@ -21,10 +21,16 @@ files. The flag `--output_file` is always required. Additionally, either
|
||||
the output file. Allowed values:
|
||||
* `TFLITE`: TensorFlow Lite model format.
|
||||
* `GRAPHVIZ_DOT`: GraphViz `.dot` format containing a visualization of the
|
||||
graph after graph transformations.
|
||||
* Note that passing `GRAPHVIZ_DOT` to `--output_format` leads to loss
|
||||
of TFLite specific transformations. To get a final visualization
|
||||
with all graph transformations use `--dump_graphviz_dir` instead.
|
||||
graph after graph transformations. *Note: This only works when you set
|
||||
flag `experimental_new_converter=False`. Also, as this format leads to
|
||||
loss of TFLite specific transformations, we recommend that you use
|
||||
`--dump_graphviz_dir` instead to get a final visualization with all
|
||||
graph transformations.*
|
||||
* `--experimental_new_converter`. Type: bool. Default: True (from TF 2.2). To
|
||||
leverage MLIR-based conversion, Google's cutting edge compiler technology
|
||||
for machine learning. This enables conversion of new classes of models,
|
||||
including Mask R-CNN, Mobile BERT, etc and supports models with functional
|
||||
control flow.
|
||||
|
||||
The following flags specify optional parameters when using SavedModels.
|
||||
|
||||
@ -73,13 +79,12 @@ based on index.
|
||||
quantized input, the quantized input would be immediately dequantized by
|
||||
the inference code according to the above formula, before proceeding
|
||||
with float inference.
|
||||
* When performing quantized inference (`inference_type`
|
||||
is`INT8`or`UINT8`), no dequantization is performed by the inference
|
||||
code. However, the quantization parameters of all arrays, including
|
||||
those of the input arrays as specified by`mean_value`and`std_dev_value`,
|
||||
determine the fixed-point multipliers used in the quantized inference
|
||||
code.`mean_value` must be an integer when performing quantized
|
||||
inference.
|
||||
* When performing quantized inference (`inference_type` is `INT8` or
|
||||
`UINT8`), no dequantization is performed by the inference code. However,
|
||||
the quantization parameters of all arrays, including those of the input
|
||||
arrays as specified by `mean_value` and `std_dev_value`, determine the
|
||||
fixed-point multipliers used in the quantized inference code.The
|
||||
`mean_value` must be an integer when performing quantized inference.
|
||||
|
||||
## Transformation flags
|
||||
|
||||
@ -123,9 +128,14 @@ have.
|
||||
accuracy. They are intended for easy experimentation with quantization via
|
||||
"dummy quantization".
|
||||
|
||||
* `--drop_control_dependency`. Type: boolean. Default: True. Indicates whether
|
||||
to drop control dependencies silently. This is due to TensorFlow Lite not
|
||||
supporting control dependencies.
|
||||
* `--post_training_quantize`. Type: boolean. Default: False. Boolean
|
||||
indicating whether to quantize the weights of the converted float model.
|
||||
Model size will be reduced and there will be latency improvements (at the
|
||||
cost of accuracy).
|
||||
|
||||
* `--quantize_to_float16`. Type: boolean. Default: False. Boolean indicating
|
||||
whether to quantize weights to fp16 instead of the default int8 when
|
||||
`--post_training_quantize=True`.
|
||||
|
||||
* `--reorder_across_fake_quant`. Type: boolean. Default: False. Indicates
|
||||
whether to reorder FakeQuant nodes in unexpected locations. Used when the
|
||||
@ -133,15 +143,29 @@ have.
|
||||
necessary to convert the graph. Results in a graph that differs from the
|
||||
quantized training graph, potentially causing differing arithmetic behavior.
|
||||
|
||||
* `--allow_custom_ops`. Type: string. Default: False. Indicates whether to
|
||||
allow custom operations. When false, any unknown operation is an error. When
|
||||
true, custom ops are created for any op that is unknown. The developer will
|
||||
need to provide these to the TensorFlow Lite runtime with a custom resolver.
|
||||
* `--change_concat_input_ranges`. Type: boolean. Default: False. Boolean to
|
||||
change behavior of min/max ranges for inputs and outputs of the concat
|
||||
operator for quantized models. Changes the ranges of concat operator overlap
|
||||
when true.
|
||||
|
||||
* `--post_training_quantize`. Type: boolean. Default: False. Boolean
|
||||
indicating whether to quantize the weights of the converted float model.
|
||||
Model size will be reduced and there will be latency improvements (at the
|
||||
cost of accuracy).
|
||||
* `--drop_control_dependency`. Type: boolean. Default: True. Indicates whether
|
||||
to drop control dependencies silently. This is due to TensorFlow Lite not
|
||||
supporting control dependencies.
|
||||
|
||||
* `--target_ops`. Type: string. Default: TFLITE_BUILTINS. Experimental flag,
|
||||
subject to change. Set of OpsSet options indicating which converter to use.
|
||||
Options: TF LITE_BUILTINS,SELECT_TF_OPS,TFLITE_BUILTINS_INT8,EXPER
|
||||
IMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8 . One or more option
|
||||
may be specified.
|
||||
|
||||
* `--allow_custom_ops`. Type: bool. Default: False. Indicates whether to allow
|
||||
custom operations. When False, any unknown operation is an error. When True,
|
||||
custom ops are created for any op that is unknown. The developer will need
|
||||
to provide these to the TensorFlow Lite runtime with a custom resolver.
|
||||
|
||||
* `--custom_opdefs`. Type: string. String representing a list of custom ops
|
||||
OpDefs delineated with commas that are included in the GraphDef. Required
|
||||
when using custom operations with `--experimental_new_converter`.
|
||||
|
||||
## Logging flags
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user