[PYTHON] How to convert Tensorflow model to Lite

About Tensorflow Lite

A set of machine learning tools for smartphones and embedded devices! Lighter than Tensorflow.

About conversion method

It is assumed that Python and Tensorflow (pip) are installed on your PC. First, prepare the model to be converted.

Convert on python

sample

import tensorflow as tf

converter = tf.lite.TFLiteConverter.from_saved_model("test_model.pb")
tflite_model = converter.convert()
open("test_model.tflite", "wb").write(tflite_model)

How to use

import tensorflow as tf

converter = tf.lite.TFLiteConverter.from_saved_model("Relative path to the model")
tflite_model = converter.convert()
open("Where to save the model", "wb").write(tflite_model)

Convert on command line

You can also convert on the command line.

sample

tflite_convert \
  --saved_model_dir=test_model.pb \
  --output_file=test_model.tflite

How to use

tflite_convert \
  --saved_model_dir=Relative path to the model\
  --output_file=Where to save the model

Finally

I will explain how to incorporate Tensorflow Lite into Android, so if you like, please do. The article is here

Also, please refer to the official information. Official article

Recommended Posts

How to convert Tensorflow model to Lite
[Tensorflowjs_converter] How to convert Tensorflow model to Tensorflow.js format
How to convert 0.5 to 1056964608 in one shot
How to install TensorFlow on CentOS 7
How to convert from .mgz to .nii.gz
How to run TensorFlow 1.0 code in 2.0
[Python] How to convert db file to csv
[Python] How to convert a 2D list to a 1D list
How to convert csv to tsv in CLI
How to use tensorflow under docker environment
How to convert DateTimeField format in Django
Convert to HSV
[Python --open3d] How to convert obj data of 3D model to point cloud
How to convert m4a acquired by iTunes to wav
How to run CNN in 1 system notation in Tensorflow 2
How to convert SVG to PDF and PNG [Python]
Tensorflow, Tensorflow After all, which one (How to read Tensorflow)
How to convert (32,32,3) to 4D tensor (1,32,32,1) with ndarray type
[TF] How to build Tensorflow in Proxy environment
[PyTorch] Sample ⑧ ~ How to build a complex model ~
Learn how to inflate images from TensorFlow code
How to force build TensorFlow 2.3.0 for CUDA11 + cuDNN8
How to use xml.etree.ElementTree
How to improve model metric monitoring in Amazon SageMaker
How to convert / restore a string with [] in python
How to use virtualenv
Scraping 2 How to scrape
How to use Seaboan
How to use image-match
How to use shogun
How to get multiple model objects randomly in Django
How to convert Python # type for Python super beginners: str
How to install Python
How to use Pandas 2
How to use Keras ~ From simple model generation to CNN ~
Convert 202003 to 2020-03 with pandas
How to read PyPI
How to install pip
How to use Virtualenv
How to use numpy.vectorize
How to update easy_install
How to install archlinux
Convert kanji to kana
How to use pytest_report_header
How to convert horizontally held data to vertically held data with pandas
How to convert a class object to a dictionary with SQLAlchemy
Convert jupyter to py
How to visualize the decision tree model of scikit-learn
How to restart gunicorn
How to install python
How to virtual host
How to debug selenium
How to use partial
Convert keras-yolo3 to onnx
How to use TensorFlow on GPUs less than Titan
How to read JSON
How to share folders with Docker and Windows with tensorflow
How to use SymPy
How to convert floating point numbers to binary numbers in Python
How to use x-means
I made a code to convert illustration2vec to keras model