tutorials/model_conversion/options.ipynb (115 lines of code) (raw):

{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "There are quite a lot options in `TFLiteConverter`. Before introducing them in detail, let's classify them into different groups first.\n", "\n", "There are generally four types of options, which can be listed as below.\n", "- Debugging options\n", " The options used for debugging purposes.\n", "- Graph options\n", " The options that affect the compute graph.\n", "- Quantization-related options\n", " The options that relates to quantization. They will be discussed in the [quantization](../quantization) tutorials.\n", "\n", "First, we will go through the debugging options." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Debugging options\n", "\n", "### dump_jit_model_path\n", "dump_jit_model_path (typing.Optional[str]): The path for dumping the jit model. Defaults to None\n", "\n", "When you specify `dump_jit_model_path`, the TorchScript model will be saved to the given file path before converting to TFLite.\n", "\n", "### dump_dummy_input_path\n", "dump_dummy_input_path (typing.Optional[str]): The path for dumping the dummy input. Defaults to None\n", "\n", "When you specify `dump_dummy_input_path`, the inputs to the model will be saved as the NumPy zipped format `*.npz` to the given file path before converting to TFLite.\n", "\n", "### dump_config_path\n", "dump_config_path (typing.Optional[str]): The path for dumping the json config. Defaults to None\n", "\n", "When you specify `dump_config_path`, the configuration of the converter will be saved as the JSON format to the given file path before converting to TFLite. Please make sure \n", "`dump_jit_model_path` is also specified.\n", "\n", "### preserve_tensors\n", "preserve_tensors (bool): Preserve the copies of the intermediate tensors. Defaults to False\n", "\n", "When you specify `preserve_tensors`, all the intermediate tensors will be preserved, so that you may get the values through `converter.get_output(name)`. This option is used when performing layerwise comparison. For more details, please refer to [the example code](../../examples/converter/convert_and_compare.py)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we will take about the graph options." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Graph options\n", "\n", "### nchw_transpose\n", "nchw_transpose (bool): Whether to perform nchw->nhwc transposes on input and output tensors. When `False` is specified, the arguments `input_transpose` and `output_transpose` will be ignored. Defaults to True\n", "\n", "### input_transpose\n", "input_transpose (typing.Optional[typing.Union[bool, typing.Iterable[bool]]], optional): Whether to transpose the input(s). Defaults to None(True for 4d-input, False otherwise).\n", "\n", "Note: `input_transpose` is ignored if `nchw_transpose=False`\n", "\n", "### output_transpose\n", "output_transpose (typing.Optional[typing.Union[bool, typing.Iterable[bool]]], optional): Whether to transpose the output(s). Defaults to None(True for 4d-input, False otherwise).\n", "\n", "Note: `output_transpose` is ignored if `nchw_transpose=False`\n", "\n", "### optimize\n", "optimize (int): The level of graph optimization. Defaults to `GraphOptimizer.ALL_OPTIMIZE`\n", "\n", "The optimizer levels are listed below.\n", "- `NO_OPTIMIZE`\n", " No optimization is performed\n", "- `FOLD_BUFFER`\n", " Only constant folding is performed\n", "- `FUSE_BN`\n", " Fuse batch normalization with convolution and fully connected layers\n", "- `COMMON_OPTIMIZE`\n", " Common optimizations like consecutive transpose/reshape/slice and no-op fusion/elimination\n", "- `BRANCH_OPTIMIZE`\n", " Enable elementwise passthrough passes which apply to branch nodes\n", "- `BRANCH_OPTIMIZE_EXTENDED`\n", " Enable the extended version of elementwise passthrough passes which apply to branch nodes\n", "- `ALL_OPTIMIZE`\n", " Full optimization\n", "\n", "It is often used in layerwise result comparison. Generally speaking, the more optimizations enabled, the less number of nodes that are shared between the PyTorch model and the TFLite model.\n", "\n", "### group_conv_rewrite\n", "group_conv_rewrite (bool): Rewriting for group convolution. Defaults to False\n", "\n", "You have to set it to `True` if you want to run the models on standard TFLite backends when you have group convolutions in your model.\n", "\n", "### tflite_micro_rewrite\n", "tflite_micro_rewrite (bool): Rewriting for running on TFLite-micro. Defaults to False\n", "\n", "There are specific constraints for running on TFLite Micro, such as the number of input tensors of the `CONCATENATION` operator cannot exceed 10. When you have such nodes (especially when you have group convolution), please set it to `True`." ] } ], "metadata": { "language_info": { "name": "python" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }