Larq Compute Engine Converter¶
The LCE converter allows you to convert a Keras model built with larq
to an LCE-compatible TensorFlow Lite FlatBuffer format for inference.
Installation¶
Before installing the LCE converter, please install:
- Python version
3.6
,3.7
, or3.8
- Tensorflow version
1.14
,1.15
,2.0
,2.1
,2.2
or2.3
(recommended):pip install tensorflow # or tensorflow-gpu
You can install the LCE converter with Python's pip package manager:
pip install larq-compute-engine
API documentation¶
convert_keras_model¶
larq_compute_engine.convert_keras_model(
model,
*,
inference_input_type=tf.float32,
inference_output_type=tf.float32,
experimental_default_int8_range=None,
experimental_enable_bitpacked_activations=False
)
Converts a Keras model to TFLite flatbuffer.
Example
tflite_model = convert_keras_model(model)
with open("/tmp/my_model.tflite", "wb") as f:
f.write(tflite_model)
Arguments
- model
tf.keras.Model
: The model to convert. - inference_input_type
tf.dtypes.DType
: Data type of the input layer. Defaults totf.float32
, must be eithertf.float32
ortf.int8
. - inference_output_type
tf.dtypes.DType
: Data type of the output layer. Defaults totf.float32
, must be eithertf.float32
ortf.int8
. - experimental_default_int8_range
Optional[Tuple[float, float]]
: Tuple of integers representing(min, max)
range values for all arrays without a specified range. Intended for experimenting with quantization via "dummy quantization". (default None) - experimental_enable_bitpacked_activations
bool
: Enable an experimental converter optimisation that attempts to reduce intermediate activation memory usage by bitpacking the activation tensor between consecutive binary convolutions where possible.
Returns
The converted data in serialized format.