{"id":15159398,"url":"https://github.com/pinto0309/tflite2tensorflow","last_synced_at":"2025-09-30T09:30:46.222Z","repository":{"id":41284665,"uuid":"330344191","full_name":"PINTO0309/tflite2tensorflow","owner":"PINTO0309","description":"Generate saved_model, tfjs, tf-trt, EdgeTPU, CoreML, quantized tflite, ONNX, OpenVINO, Myriad Inference Engine blob and .pb from .tflite. Support for building environments with Docker. It is possible to directly access the host PC GUI and the camera to verify the operation. NVIDIA GPU (dGPU) support.  Intel iHD GPU (iGPU) support. Supports inverse quantization of INT8 quantization model.","archived":true,"fork":false,"pushed_at":"2022-09-04T03:56:54.000Z","size":35487,"stargazers_count":268,"open_issues_count":1,"forks_count":42,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-01-16T17:37:27.439Z","etag":null,"topics":["converter","coreml","depthai","docker","edgetpu","mediapipe","models-conver","models-converter","onnx","openvino","tensorflow","tensorflow-lite","tensorflow-models","tensorflowjs","tensorrt","tf-trt","tfjs","tflite"],"latest_commit_sha":null,"homepage":"https://qiita.com/PINTO","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PINTO0309.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"PINTO0309","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-01-17T08:13:43.000Z","updated_at":"2024-12-05T23:05:12.000Z","dependencies_parsed_at":"2022-08-10T01:43:31.306Z","dependency_job_id":null,"html_url":"https://github.com/PINTO0309/tflite2tensorflow","commit_stats":null,"previous_names":[],"tags_count":113,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Ftflite2tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Ftflite2tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Ftflite2tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Ftflite2tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PINTO0309","download_url":"https://codeload.github.com/PINTO0309/tflite2tensorflow/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234722055,"owners_count":18876896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["converter","coreml","depthai","docker","edgetpu","mediapipe","models-conver","models-converter","onnx","openvino","tensorflow","tensorflow-lite","tensorflow-models","tensorflowjs","tensorrt","tf-trt","tfjs","tflite"],"created_at":"2024-09-26T21:20:58.233Z","updated_at":"2025-09-30T09:30:39.965Z","avatar_url":"https://github.com/PINTO0309.png","language":"Python","funding_links":["https://github.com/sponsors/PINTO0309"],"categories":[],"sub_categories":[],"readme":"# tflite2tensorflow\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/33194443/105187518-38ac0c00-5b76-11eb-869b-b518df146924.png\" /\u003e\n\u003c/p\u003e\n\nGenerate saved_model, tfjs, tf-trt, EdgeTPU, CoreML, quantized tflite, ONNX, OpenVINO, Myriad Inference Engine blob and .pb from .tflite. Support for building environments with Docker. It is possible to directly access the host PC GUI and the camera to verify the operation. NVIDIA GPU (dGPU) support. Intel iHD GPU (iGPU) support. Supports inverse quantization of INT8 quantization model.\n\n[Special custom TensorFlow binaries](https://github.com/PINTO0309/Tensorflow-bin) and [special custom TensorFLow Lite binaries](https://github.com/PINTO0309/TensorflowLite-bin) are used.\n\n[![Downloads](https://static.pepy.tech/personalized-badge/tflite2tensorflow?period=total\u0026units=none\u0026left_color=grey\u0026right_color=brightgreen\u0026left_text=Downloads)](https://pepy.tech/project/tflite2tensorflow) ![GitHub](https://img.shields.io/github/license/PINTO0309/tflite2tensorflow?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/tflite2tensorflow?color=2BAF2B)](https://pypi.org/project/tflite2tensorflow/) [![CodeQL](https://github.com/PINTO0309/tflite2tensorflow/workflows/CodeQL/badge.svg)](https://github.com/PINTO0309/tflite2tensorflow/actions?query=workflow%3ACodeQL)\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/33194443/166147152-79cd691e-7b47-4338-acee-34791ac2d1f3.gif\" /\u003e\n\u003c/p\u003e\n\n## 1. Supported Layers\n\n  **\u003cdetails\u003e\u003csummary\u003eSupported Layers\u003c/summary\u003e\u003cdiv\u003e**\n\n  |No.|TFLite Layer|TF Layer|Remarks|\n  |:--:|:--|:--|:--|\n  |1|CONV_2D|tf.nn.conv2d||\n  |2|DEPTHWISE_CONV_2D|tf.nn.depthwise_conv2d||\n  |3|MAX_POOL_2D|tf.nn.max_pool||\n  |4|PAD|tf.pad||\n  |5|MIRROR_PAD|tf.raw_ops.MirrorPad||\n  |6|RELU|tf.nn.relu||\n  |7|PRELU|tf.keras.layers.PReLU||\n  |8|RELU6|tf.nn.relu6||\n  |9|RESHAPE|tf.reshape||\n  |10|ADD|tf.add||\n  |11|SUB|tf.math.subtract||\n  |12|CONCATENATION|tf.concat||\n  |13|LOGISTIC|tf.math.sigmoid||\n  |14|TRANSPOSE_CONV|tf.nn.conv2d_transpose||\n  |15|MUL|tf.multiply||\n  |16|HARD_SWISH|x\\*tf.nn.relu6(x+3)\\*0.16666667 Or x\\*tf.nn.relu6(x+3)\\*0.16666666||\n  |17|AVERAGE_POOL_2D|tf.keras.layers.AveragePooling2D||\n  |18|FULLY_CONNECTED|tf.keras.layers.Dense||\n  |19|RESIZE_BILINEAR|tf.image.resize Or tf.image.resize_bilinear|The behavior differs depending on the optimization options of openvino and edgetpu.|\n  |20|RESIZE_NEAREST_NEIGHBOR|tf.image.resize Or tf.image.resize_nearest_neighbor|The behavior differs depending on the optimization options of openvino and edgetpu.|\n  |21|MEAN|tf.math.reduce_mean||\n  |22|SQUARED_DIFFERENCE|tf.math.squared_difference||\n  |23|RSQRT|tf.math.rsqrt||\n  |24|DEQUANTIZE|(const)||\n  |25|FLOOR|tf.math.floor||\n  |26|TANH|tf.math.tanh||\n  |27|DIV|tf.math.divide||\n  |28|FLOOR_DIV|tf.math.floordiv||\n  |29|SUM|tf.math.reduce_sum||\n  |30|POW|tf.math.pow||\n  |31|SPLIT|tf.split||\n  |32|SOFTMAX|tf.nn.softmax||\n  |33|STRIDED_SLICE|tf.strided_slice||\n  |34|TRANSPOSE|ttf.transpose||\n  |35|SPACE_TO_DEPTH|tf.nn.space_to_depth||\n  |36|DEPTH_TO_SPACE|tf.nn.depth_to_space||\n  |37|REDUCE_MAX|tf.math.reduce_max||\n  |38|Convolution2DTransposeBias|tf.nn.conv2d_transpose, tf.math.add|CUSTOM, MediaPipe|\n  |39|LEAKY_RELU|tf.keras.layers.LeakyReLU||\n  |40|MAXIMUM|tf.math.maximum||\n  |41|MINIMUM|tf.math.minimum||\n  |42|MaxPoolingWithArgmax2D|tf.raw_ops.MaxPoolWithArgmax|CUSTOM, MediaPipe|\n  |43|MaxUnpooling2D|tf.cast, tf.shape, tf.math.floordiv, tf.math.floormod, tf.ones_like, tf.shape, tf.concat, tf.reshape, tf.transpose, tf.scatter_nd|CUSTOM, MediaPipe|\n  |44|GATHER|tf.gather||\n  |45|CAST|tf.cast||\n  |46|SLICE|tf.slice||\n  |47|PACK|tf.stack||\n  |48|UNPACK|tf.unstack||\n  |49|ARG_MAX|tf.math.argmax Or tf.math.reduce_max, tf.subtract, tf.math.minimum, tf.multiply|The behavior differs depending on the optimization options of edgetpu.|\n  |50|EXP|tf.exp||\n  |51|TOPK_V2|tf.math.top_k||\n  |52|LOG_SOFTMAX|tf.nn.log_softmax||\n  |53|L2_NORMALIZATION|tf.math.l2_normalize||\n  |54|LESS|tf.math.less||\n  |55|LESS_EQUAL|tf.math.less_equal||\n  |56|GREATER|tf.math.greater||\n  |57|GREATER_EQUAL|tf.math.greater_equal||\n  |58|NEG|tf.math.negative||\n  |59|WHERE|tf.where||\n  |60|SELECT|tf.where||\n  |61|SELECT_V2|tf.where||\n  |62|PADV2|tf.raw_ops.PadV2||\n  |63|SIN|tf.math.sin||\n  |64|TILE|tf.tile||\n  |65|EQUAL|tf.math.equal||\n  |66|NOT_EQUAL|tf.math.not_equal||\n  |67|LOG|tf.math.log||\n  |68|SQRT|tf.math.sqrt||\n  |69|ARG_MIN|tf.math.argmin or tf.math.negative,tf.math.argmax||\n  |70|REDUCE_PROD|tf.math.reduce_prod||\n  |71|LOGICAL_OR|tf.math.logical_or||\n  |72|LOGICAL_AND|tf.math.logical_and||\n  |73|LOGICAL_NOT|tf.math.logical_not||\n  |74|REDUCE_MIN|tf.math.reduce_min or tf.math.negative,tf.math.reduce_max||\n  |75|REDUCE_ANY|tf.math.reduce_any||\n  |76|SQUARE|tf.math.square||\n  |77|ZEROS_LIKE|tf.zeros_like||\n  |78|FILL|tf.fill||\n  |79|FLOOR_MOD|tf.math.floormod||\n  |80|RANGE|tf.range||\n  |81|ABS|tf.math.abs||\n  |82|UNIQUE|tf.unique||\n  |83|CEIL|tf.math.ceil||\n  |84|REVERSE_V2|tf.reverse||\n  |85|ADD_N|tf.math.add_n||\n  |86|GATHER_ND|tf.gather_nd||\n  |87|COS|tf.math.cos||\n  |88|RANK|tf.math.rank||\n  |89|ELU|tf.nn.elu||\n  |90|WHILE|tf.while_loop||\n  |91|REVERSE_SEQUENCE|tf.reverse_sequence||\n  |92|MATRIX_DIAG|tf.linalg.diag||\n  |93|ROUND|tf.math.round||\n  |94|NON_MAX_SUPPRESSION_V4|tf.raw_ops.NonMaxSuppressionV4||\n  |95|NON_MAX_SUPPRESSION_V5|tf.raw_ops.NonMaxSuppressionV5, tf.raw_ops.NonMaxSuppressionV4, tf.raw_ops.NonMaxSuppressionV3||\n  |96|SCATTER_ND|tf.scatter_nd||\n  |97|SEGMENT_SUM|tf.math.segment_sum||\n  |98|CUMSUM|tf.math.cumsum||\n  |99|BROADCAST_TO|tf.broadcast_to||\n  |100|RFFT2D|tf.signal.rfft2d||\n  |101|L2_POOL_2D|tf.square, tf.keras.layers.AveragePooling2D, tf.sqrt||\n  |102|LOCAL_RESPONSE_NORMALIZATION|tf.nn.local_response_normalization||\n  |103|RELU_N1_TO_1|tf.minimum, tf.maximum||\n  |104|SPLIT_V|tf.raw_ops.SplitV||\n  |105|MATRIX_SET_DIAG|tf.linalg.set_diag||\n  |106|SHAPE|tf.shape||\n  |107|EXPAND_DIMS|tf.expand_dims||\n  |108|SQUEEZE|tf.squeeze||\n  |109|FlexRFFT|tf.signal.rfft|Flex OP|\n  |110|FlexImag|tf.math.imag|Flex OP|\n  |111|FlexReal|tf.math.real|Flex OP|\n  |112|FlexRFFT2D|tf.signal.rfft2d|Flex OP|\n  |113|FlexComplexAbs|tf.raw_ops.ComplexAbs|Flex OP|\n  |114|IMAG|tf.math.imag||\n  |115|REAL|tf.math.real||\n  |116|COMPLEX_ABS|tf.raw_ops.ComplexAbs||\n  |117|TFLite_Detection_PostProcess|tf.divide, tf.strided_slice, tf.math.argmax, tf.math.reduce_max, tf.math.multiply, tf.math.add, tf.math.exp, tf.math.subtract, tf.expand_dims, tf.gather, tf.reshape, tf.identity, tf.raw_ops.NonMaxSuppressionV5|CUSTOM|\n  |118|ONE_HOT|tf.one_hot||\n  |119|FlexMultinomial|tf.random.categorical|Flex OP|\n  |120|FlexAll|tf.math.reduce_all|Flex OP|\n  |121|FlexErf|tf.math.erf|Flex OP|\n  |122|FlexRoll|tf.roll|Flex OP|\n  |123|CONV_3D|tf.keras.layers.Conv3D||\n  |124|CONV_3D_TRANSPOSE|tf.nn.conv3d_transpose||\n  |125|Densify|(const)||\n  |126|SPACE_TO_BATCH_ND|tf.space_to_batch_nd||\n  |127|BATCH_TO_SPACE_ND|tf.compat.v1.batch_to_space_nd||\n  |128|TransformLandmarks|tf.reshape, tf.linalg.matmul, tf.math.add|CUSTOM, MediaPipe|\n  |129|TransformTensorBilinear|tf.reshape, tf.linalg.matmul, tf.math.add, tf.tile, tf.math.floor, tf.math.subtract, tf.math.multiply, tf.math.reduce_prod, tf.cast, tf.math.maximum, tf.math.maximum, tf.concat, tf.gather_nd|CUSTOM, MediaPipe|\n  |130|Landmarks2TransformMatrix|tf.constant, tf.math.subtract, tf.math.norm, tf.math.divide, tf.linalg.matmul, tf.concat, tf.transpose, tf.gather, tf.math.reduce_min, tf.math.reduce_max, tf.math.multiply, tf.zeros, tf.math.add, tf.tile|CUSTOM, MediaPipe|\n\n  \u003c/div\u003e\u003c/details\u003e\n\n## 2. Environment\n- Python3.8+\n- TensorFlow v2.9.0+\n- TensorFlow Lite v2.9.0 with MediaPipe Custom OP, FlexDelegate and XNNPACK enabled\n  - **[Add a custom OP to the TFLite runtime to build the whl installer (for Python)](https://zenn.dev/pinto0309/articles/a0e40c2817f2ee)**, **`MaxPoolingWithArgmax2D`**, **`MaxUnpooling2D`**, **`Convolution2DTransposeBias`**, **`TransformLandmarks`**, **`TransformTensorBilinear`**, **`Landmarks2TransformMatrix`**\n  - **https://github.com/PINTO0309/TensorflowLite-bin**\n- flatc v2.0.8\n- PyTorch v1.12.0 (with grid_sample)\n- TorchVision\n- TorchAudio\n- OpenVINO 2021.4.582+\n- TensorRT 8.4+\n- trtexec\n- pycuda 2021.1\n- tensorflowjs\n- coremltools\n- paddle2onnx\n- onnx\n- onnxruntime-gpu (CUDA, TensorRT, OpenVINO)\n- onnxruntime-extensions\n- onnx_graphsurgeon\n- onnx-simplifier\n- onnxconverter-common\n- onnxmltools\n- onnx-tensorrt\n- tf2onnx\n- torch2trt\n- onnx-tf\n- tensorflow-datasets\n- tf_slim\n- edgetpu_compiler\n- tflite2tensorflow\n- openvino2tensorflow\n- simple-onnx-processing-tools\n- gdown\n- pandas\n- matplotlib\n- paddlepaddle\n- paddle2onnx\n- pycocotools\n- scipy\n- Intel-Media-SDK\n- Intel iHD GPU (iGPU) support\n- OpenCL\n- gluoncv\n- LLVM\n- NNPACK\n- WSL2 OpenCL\n\n## 3. Setup\n### 3-1. **[Environment construction pattern 1]** Execution by Docker (`strongly recommended`)\nYou do not need to install any packages other than Docker. It consumes about 26.7GB of host storage.\n```bash\n$ docker pull ghcr.io/pinto0309/tflite2tensorflow:latest\nor\n$ docker build -t ghcr.io/pinto0309/tflite2tensorflow:latest .\n\n# If you don't need to access the GUI of the HostPC and the USB camera.\n$ docker run -it --rm \\\n  -v `pwd`:/home/user/workdir \\\n  ghcr.io/pinto0309/tflite2tensorflow:latest\n\n# If conversion to TF-TRT is not required. And if you need to access the HostPC GUI and USB camera.\n$ xhost +local: \u0026\u0026 \\\n  docker run -it --rm \\\n  -v `pwd`:/home/user/workdir \\\n  -v /tmp/.X11-unix/:/tmp/.X11-unix:rw \\\n  --device /dev/video0:/dev/video0:mwr \\\n  --net=host \\\n  -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \\\n  -e DISPLAY=$DISPLAY \\\n  --privileged \\\n  ghcr.io/pinto0309/tflite2tensorflow:latest\n\n# If you need to convert to TF-TRT. And if you need to access the HostPC GUI and USB camera.\n$ xhost +local: \u0026\u0026 \\\n  docker run --gpus all -it --rm \\\n  -v `pwd`:/home/user/workdir \\\n  -v /tmp/.X11-unix/:/tmp/.X11-unix:rw \\\n  --device /dev/video0:/dev/video0:mwr \\\n  --net=host \\\n  -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \\\n  -e DISPLAY=$DISPLAY \\\n  --privileged \\\n  ghcr.io/pinto0309/tflite2tensorflow:latest\n\n# If you are using iGPU (OpenCL). And if you need to access the HostPC GUI and USB camera.\n$ xhost +local: \u0026\u0026 \\\n  docker run -it --rm \\\n  -v `pwd`:/home/user/workdir \\\n  -v /tmp/.X11-unix/:/tmp/.X11-unix:rw \\\n  --device /dev/video0:/dev/video0:mwr \\\n  --net=host \\\n  -e LIBVA_DRIVER_NAME=iHD \\\n  -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \\\n  -e DISPLAY=$DISPLAY \\\n  --privileged \\\n  ghcr.io/pinto0309/tflite2tensorflow:latest\n```\n### 3-2. **[Environment construction pattern 2]** Execution by Host machine\nTo install using the Python Package Index (PyPI), use the following command.\n```\n$ pip3 install --user --upgrade tflite2tensorflow\n```\nOr, To install with the latest source code of the main branch, use the following command.\n```\n$ pip3 install --user --upgrade git+https://github.com/PINTO0309/tflite2tensorflow\n```\nInstalls a customized TensorFlow Lite runtime with support for MediaPipe Custom OP, FlexDelegate, and XNNPACK. If tflite_runtime does not install properly, please follow the instructions in the next article to build a custom build in the environment you are using. **[Add a custom OP to the TFLite runtime to build the whl installer (for Python)](https://zenn.dev/pinto0309/articles/a0e40c2817f2ee)**, **`MaxPoolingWithArgmax2D`**, **`MaxUnpooling2D`**, **`Convolution2DTransposeBias`**, **`TransformLandmarks`**, **`TransformTensorBilinear`**, **`Landmarks2TransformMatrix`**\n```\n$ sudo pip3 uninstall -y \\\n    tensorboard-plugin-wit \\\n    tb-nightly \\\n    tensorboard \\\n    tf-estimator-nightly \\\n    tensorflow-gpu \\\n    tensorflow \\\n    tf-nightly \\\n    tensorflow_estimator \\\n    tflite_runtime\n\n$ APPVER=v1.20.7\n$ TENSORFLOWVER=2.8.0\n\n### Customized version of TensorFlow Lite installation\n$ wget https://github.com/PINTO0309/tflite2tensorflow/releases/download/${APPVER}/tflite_runtime-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl \\\n  \u0026\u0026 sudo chmod +x tflite_runtime-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl \\\n  \u0026\u0026 pip3 install --user --force-reinstall tflite_runtime-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl \\\n  \u0026\u0026 rm tflite_runtime-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl\n\n### Install the Customized Full TensorFlow package\n### (MediaPipe Custom OP, FlexDelegate, XNNPACK enabled)\n$ wget https://github.com/PINTO0309/tflite2tensorflow/releases/download/${APPVER}/tflite_runtime-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl \\\n  \u0026\u0026 sudo chmod +x tensorflow-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl \\\n  \u0026\u0026 pip3 install --user --force-reinstall tensorflow-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl \\\n  \u0026\u0026 rm tensorflow-${TENSORFLOWVER}-cp38-none-linux_x86_64.whl\n\n or\n\n### Install the Non-customized TensorFlow package\n$ pip3 install --user tf-nightly\n\n### Download schema.fbs\n$ wget https://github.com/PINTO0309/tflite2tensorflow/raw/main/schema/schema.fbs\n```\n### Build flatc\n```\n$ git clone -b v2.0.8 https://github.com/google/flatbuffers.git\n$ cd flatbuffers \u0026\u0026 mkdir build \u0026\u0026 cd build\n$ cmake -G \"Unix Makefiles\" -DCMAKE_BUILD_TYPE=Release ..\n$ make -j$(nproc)\n```\n\n![vvtvsu0y1791ow2ybdk61s9fv7e4](https://user-images.githubusercontent.com/33194443/105578192-badc4080-5dc1-11eb-8fda-4eaf0d8a63e4.png)\n![saxqukktcjncsk2hp7m8p2cns4q4](https://user-images.githubusercontent.com/33194443/105578219-d6dfe200-5dc1-11eb-9026-42104fdcc727.png)\n\nThe Windows version of flatc v2.0.8 can be downloaded from here.\n**https://github.com/google/flatbuffers/releases/download/v2.0.8/Windows.flatc.binary.zip**\n\n## 4. Usage / Execution sample\n### 4-1. Command line options\n```\nusage: tflite2tensorflow\n  [-h]\n  --model_path MODEL_PATH\n  --flatc_path FLATC_PATH\n  --schema_path SCHEMA_PATH\n  [--model_output_path MODEL_OUTPUT_PATH]\n  [--output_pb]\n  [--output_no_quant_float32_tflite]\n  [--output_dynamic_range_quant_tflite]\n  [--output_weight_quant_tflite]\n  [--output_float16_quant_tflite]\n  [--output_integer_quant_tflite]\n  [--output_full_integer_quant_tflite]\n  [--output_integer_quant_type]\n  [--string_formulas_for_normalization STRING_FORMULAS_FOR_NORMALIZATION]\n  [--calib_ds_type CALIB_DS_TYPE]\n  [--ds_name_for_tfds_for_calibration DS_NAME_FOR_TFDS_FOR_CALIBRATION]\n  [--split_name_for_tfds_for_calibration SPLIT_NAME_FOR_TFDS_FOR_CALIBRATION]\n  [--download_dest_folder_path_for_the_calib_tfds DOWNLOAD_DEST_FOLDER_PATH_FOR_THE_CALIB_TFDS]\n  [--tfds_download_flg]\n  [--load_dest_file_path_for_the_calib_npy LOAD_DEST_FILE_PATH_FOR_THE_CALIB_NPY]\n  [--output_tfjs]\n  [--output_tftrt_float32]\n  [--output_tftrt_float16]\n  [--output_coreml]\n  [--optimizing_coreml]\n  [--output_edgetpu]\n  [--edgetpu_compiler_timeout EDGETPU_COMPILER_TIMEOUT]\n  [--edgetpu_num_segments EDGETPU_NUM_SEGMENTS]\n  [--output_onnx]\n  [--onnx_opset ONNX_OPSET]\n  [--onnx_extra_opset ONNX_EXTRA_OPSET]\n  [--disable_onnx_nchw_conversion]\n  [--disable_onnx_optimization]\n  [--output_openvino_and_myriad]\n  [--vpu_number_of_shaves VPU_NUMBER_OF_SHAVES]\n  [--vpu_number_of_cmx_slices VPU_NUMBER_OF_CMX_SLICES]\n  [--optimizing_for_openvino_and_myriad]\n  [--rigorous_optimization_for_myriad]\n  [--replace_swish_and_hardswish]\n  [--optimizing_for_edgetpu]\n  [--replace_prelu_and_minmax]\n  [--disable_experimental_new_quantizer]\n  [--disable_per_channel]\n  [--optimizing_barracuda]\n  [--locationids_of_the_terminating_output]\n\noptional arguments:\n  -h, --help\n          show this help message and exit\n  --model_path MODEL_PATH\n          input tflite model path (*.tflite)\n  --flatc_path FLATC_PATH\n          flatc file path (flatc)\n  --schema_path SCHEMA_PATH\n          schema.fbs path (schema.fbs)\n  --model_output_path MODEL_OUTPUT_PATH\n          The output folder path of the converted model file\n  --output_pb\n          .pb output switch\n  --output_no_quant_float32_tflite\n          float32 tflite output switch\n  --output_dynamic_range_quant_tflite\n          dynamic range quant tflite output switch\n  --output_weight_quant_tflite\n          weight quant tflite output switch\n  --output_float16_quant_tflite\n          float16 quant tflite output switch\n  --output_integer_quant_tflite\n          integer quant tflite output switch\n  --output_full_integer_quant_tflite\n          full integer quant tflite output switch\n  --output_integer_quant_type OUTPUT_INTEGER_QUANT_TYPE\n          Input and output types when doing Integer Quantization\n          ('int8 (default)' or 'uint8')\n  --string_formulas_for_normalization STRING_FORMULAS_FOR_NORMALIZATION\n          String formulas for normalization. It is evaluated by\n          Python's eval() function. Default: '(data -\n          [127.5,127.5,127.5]) / [127.5,127.5,127.5]'\n  --calib_ds_type CALIB_DS_TYPE\n          Types of data sets for calibration. tfds or numpy\n          Default: numpy\n  --ds_name_for_tfds_for_calibration DS_NAME_FOR_TFDS_FOR_CALIBRATION\n          Dataset name for TensorFlow Datasets for calibration.\n          https://www.tensorflow.org/datasets/catalog/overview\n  --split_name_for_tfds_for_calibration SPLIT_NAME_FOR_TFDS_FOR_CALIBRATION\n          Split name for TensorFlow Datasets for calibration.\n          https://www.tensorflow.org/datasets/catalog/overview\n  --download_dest_folder_path_for_the_calib_tfds DOWNLOAD_DEST_FOLDER_PATH_FOR_THE_CALIB_TFDS\n          Download destination folder path for the calibration\n          dataset. Default: $HOME/TFDS\n  --tfds_download_flg\n          True to automatically download datasets from\n          TensorFlow Datasets. True or False\n  --load_dest_file_path_for_the_calib_npy LOAD_DEST_FILE_PATH_FOR_THE_CALIB_NPY\n          The path from which to load the .npy file containing\n          the numpy binary version of the calibration data.\n          Default: sample_npy/calibration_data_img_sample.npy\n          [20, 513, 513, 3] -\u003e [Number of images, h, w, c]\n  --output_tfjs\n          tfjs model output switch\n  --output_tftrt32\n          tftrt float32 model output switch\n  --output_tftrt16\n          tftrt float16 model output switch\n  --output_coreml\n          coreml model output switch\n  --optimizing_for_coreml\n          Optimizing graph for coreml\n  --output_edgetpu\n          edgetpu model output switch\n  --edgetpu_compiler_timeout\n          edgetpu_compiler timeout for one compilation process in seconds.\n          Default: 3600\n  --edgetpu_num_segments\n          Partition the model into 'num_segments' segments.\n          Default: 1 (no partition)\n  --output_onnx\n          onnx model output switch\n  --onnx_opset ONNX_OPSET\n          onnx opset version number\n  --onnx_extra_opset ONNX_EXTRA_OPSET\n          The name of the onnx 'extra_opset' to enable.\n          Default: ''\n          'com.microsoft:1' or 'ai.onnx.contrib:1' or 'ai.onnx.ml:1'\n  --disable_onnx_nchw_conversion\n          Disable onnx NCHW conversion\n  --disable_onnx_optimization\n          Disable onnx optimization\n  --output_openvino_and_myriad\n          openvino model and myriad inference engine blob output switch\n  --vpu_number_of_shaves VPU_NUMBER_OF_SHAVES\n          vpu number of shaves. Default: 4\n  --vpu_number_of_cmx_slices VPU_NUMBER_OF_CMX_SLICES\n          vpu number of cmx slices. Default: 4\n  --optimizing_for_openvino_and_myriad\n          Optimizing graph for openvino/myriad\n  --rigorous_optimization_for_myriad\n          Replace operations that are not supported by myriad with operations\n          that are as feasible as possible.\n          e.g. 'Abs' -\u003e 'Square' + 'Sqrt'\n  --replace_swish_and_hardswish\n          Replace swish and hard-swish with each other\n  --optimizing_for_edgetpu\n          Optimizing for edgetpu\n  --replace_prelu_and_minmax\n          Replace prelu and minimum/maximum with each other\n  --disable_experimental_new_quantizer\n          Disable MLIRs new quantization feature during INT8 quantization\n          in TensorFlowLite.\n  --disable_per_channel\n          Disable per-channel quantization for tflite.\n  --optimizing_barracuda\n          Generates ONNX by replacing Barracuda unsupported layers\n          with standard layers. For example, GatherND.\n  --locationids_of_the_terminating_output\n          A comma-separated list of LocationIDs to be used as output layers.\n          e.g. --locationids_of_the_terminating_output 100,201,560\n          Default: ''\n```\n### 4-2. Step 1 : Generating saved_model and FreezeGraph (.pb)\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_pb\n```\nor\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_pb \\\n  --optimizing_for_openvino_and_myriad\n```\nor\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_pb \\\n  --optimizing_for_openvino_and_myriad \\\n  --rigorous_optimization_for_myriad\n```\nor\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_pb \\\n  --optimizing_for_edgetpu\n```\nor\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_pb \\\n  --optimizing_for_coreml\n```\nor\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_pb \\\n  --optimizing_barracuda\n```\n\n### 4-3. Step 2 : Generation of quantized tflite, TFJS, TF-TRT, EdgeTPU, CoreML and ONNX\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_no_quant_float32_tflite \\\n  --output_dynamic_range_quant_tflite \\\n  --output_weight_quant_tflite \\\n  --output_float16_quant_tflite \\\n  --output_integer_quant_tflite \\\n  --string_formulas_for_normalization 'data / 255.0' \\\n  --output_tfjs \\\n  --output_coreml \\\n  --output_tftrt_float32 \\\n  --output_tftrt_float16 \\\n  --output_onnx \\\n  --onnx_opset 11 \\\n  --output_openvino_and_myriad\n```\nor\n```\n$ tflite2tensorflow \\\n  --model_path segm_full_v679.tflite \\\n  --flatc_path ../flatc \\\n  --schema_path ../schema.fbs \\\n  --output_no_quant_float32_tflite \\\n  --output_dynamic_range_quant_tflite \\\n  --output_weight_quant_tflite \\\n  --output_float16_quant_tflite \\\n  --output_integer_quant_tflite \\\n  --output_edgetpu \\\n  --output_integer_quant_typ 'uint8' \\\n  --string_formulas_for_normalization 'data / 255.0' \\\n  --output_tfjs \\\n  --output_coreml \\\n  --output_tftrt_float32 \\\n  --output_tftrt_float16 \\\n  --output_onnx \\\n  --onnx_opset 11\n```\n### 4-4. Check the contents of the .npy file, which is a binary version of the image file\n```\n$ view_npy --npy_file_path calibration_data_img_sample.npy\n```\nPress the **`Q`** button to display the next image. **`calibration_data_img_sample.npy`** contains 20 images extracted from the MS-COCO data set.\n\n![image](https://user-images.githubusercontent.com/33194443/160409583-66c45d47-636b-442c-94d6-51ad4170cc9b.png)\n\n## 5. Sample image\nThis is the result of converting MediaPipe's Meet Segmentation model (segm_full_v679.tflite / Float16 / Google Meet) to **`saved_model`** and then reconverting it to Float32 tflite. Replace the GPU-optimized **`Convolution2DTransposeBias`** layer with the standard **`TransposeConv`** and **`BiasAdd`** layers in a fully automatic manner. The weights and biases of the Float16 **`Dequantize`** layer are automatically back-quantized to Float32 precision. The generated **`saved_model`** in Float32 precision can be easily converted to **`Float16`**, **`INT8`**, **`EdgeTPU`**, **`TFJS`**, **`TF-TRT`**, **`CoreML`**, **`ONNX`**, **`OpenVINO`**, **`Myriad Inference Engine blob`**.\n\n|Before|After|\n|:--:|:--:|\n|![segm_full_v679 tflite](https://user-images.githubusercontent.com/33194443/105579124-db0efe00-5dc7-11eb-86de-19b7782ffb14.png)|![model_float32 tflite](https://user-images.githubusercontent.com/33194443/105579178-3640f080-5dc8-11eb-9e76-f98dc810022a.png)|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Ftflite2tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinto0309%2Ftflite2tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Ftflite2tensorflow/lists"}