TFLite Converter, Easy Converter?

It looks easy when you read the tutorial about convert model, with 2 lines of codes.


Yes it works, but in some conditions.

Three things that you must know about TFLite Converter before you use the converter:

1. Consider the Supported types

At that article, we know that TFLite converter doesn’t support string and float16, at least not yet.

There are some tutorials about text classification that use String for the input shape parameter at input layer, for example this tutorial provided by tensorflow. For now, you cannot convert the model from that tutorial into TFLite.

But actually you can make the text classification by encoding the text string into float or int.

2. You Can Use Tensorflow Lite Model Maker, for not Supported Input Type

If you don’t wanna make your hands dirty by encoding the text input into float or integer to make the model supported by the converter, you can create TFlite model for text classification with Tensorflow Lite Model Maker.

Tensorflow provides Some Model Makers that you can use: Image Classification, Text Classification and Question Answer.

3. Quantization Integer Only

import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
def representative_dataset_gen():
for input_value in
# Get sample input data as a numpy array in a method of your choosing.
yield [input]
converter.representative_dataset = representative_dataset_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.int8 # or tf.uint8
converter.inference_output_type = tf.int8 # or tf.uint8
tflite_quant_model = converter.convert()
  • This results in a smaller model and increased inferencing speed, which is valuable for low-power devices such as microcontrollers. This data format is also required by integer-only accelerators such as the Edge TPU.
  • This converts input and output type float 32 to uint_8.
  • Cannot use float 64 to convert to uint_8.
  • Firebase ML use uint_8 for produce tflite model.




Still believe, can change the world with code..

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Coding Period (Week 6 + Week 7)

Alternative Ways to Recommend Airbnb Listings Using Natural Language Processing

Conversational AI chatbot using Rasa NLU & Rasa Core: How Dialogue Handling with Rasa Core can use…

Traffic Signs Classification with a Convolutional Neural Network

A Simple Guide To Reinforcement Learning With The Super Mario Bros. Environment

Text generation for Floor Plan

Generative Probabilistic Modeling

ClassMix Paper Reproduction

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ade sueb

ade sueb

Still believe, can change the world with code..

More from Medium

Quick, Draw 🖌️ 🖼️

An Alternative Method of Community Detection

algorithm visualization

Tips on how to use OpenVINO™ toolkit with your favorite Deep Learning Frameworks

Projects in Medical Imaging with TensorFlow 2.X and Keras