Real-Time Sign Language Detection Android Application Using TensorFlow Lite
Real-Time Sign Language Detection Android Application Using TensorFlow Lite
in a real-time Sign language detection app. we will not cover the training part in this article
btw I used the TensorFlow object detection API for that. first, we will save the inference
model from the checkpoint which we created while training our model. this article is
helpful for those who are starting the TensorFlow lite. I hope it will be helpful. Application
link at the end of the article.
3.Then we will post quantize the graph and save the tflite model.
# save this file as postQuantization.py
def representative_dataset():
for _ in range(100):
data = np.random.rand(1, 320, 320, 3)
yield [data.astype(np.float32)]
import numpy as np
import tensorflow as tf
saved_model_dir = "output/exported_models/tflite_infernce/saved_model"
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.allow_custom_ops = True
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset
converter.inference_input_type = tf.uint8 # or tf.uint8
converter.inference_output_type = tf.uint8 # or tf.uint8
tflite_quant_model = converter.convert()
with tf.io.gfile.GFile(tf_lite_model_path, 'wb') as f:
f.write(tflite_quant_model)
4.Write metadata into the tflite model to use with the android.
''' Writing MetaData to TfLite Model
save it as MetaDataWriterFile.py
'''
ObjectDetectorWriter = object_detector.MetadataWriter
_MODEL_PATH = <tf_lite_model_path>
_LABEL_FILE = <label_path>
_SAVE_TO_PATH = <path_to_tflite_path/tflite_with_metadata.tflite>
writer = ObjectDetectorWriter.create_for_inference(
writer_utils.load_file(_MODEL_PATH), [127.5], [127.5], [_LABEL_FILE])
writer_utils.save_file(writer.populate(), _SAVE_TO_PATH)