Convert Facenet .npz trained model to tensorflow-lite (tflite) format - python

I have used combination of MTCNN (for face detection) and Facenet model is trained on different faces and have generated weights (face embedding) into .npz file. I have used Keras API to load model and train and use it for inference for further face recognition. This whole setup is working fine.
Now, I want to use the same weights for Face Recognition in Android app using Firebase AutoML custom model implementation which supports only tensorflow-lite models. So I want to convert the Facenet trained weights (face embedding in '.npz' file format) into tensorflow-lite (.tflite) model.
But I am not able to find any solution for it there are options to convert Facenet frozen model '.pb' file to convert into tflite. Click here for details.
Please help if you have any idea about this conversion.
Thanks

Related

Can you use .tflite model like you would a normal tensorflow model?

I've used tensor flow lite to make my own custom android.tflite model as described in this tflite collab demo.
I was going to test my object detection model using tflite_support, but this module is not Windows compatible.
Can I use my .tflite model with "regular" tensorflow? If so, how do I load the .tflite model? Following this example, we use tf.saved_model.load(model_dir), which I believe will not load our android.tflite file.
Is there a function for loading a .tflite file? Or while I'm making my model with tensorflow_model_maker, to I need to specify a different format for the model?
Additionally, I see that tflite has a way to convert normal tensorflow models to tflite models, but I don't see that it has a means of doing the reverse:
tf.lite.TFLiteConverter(
funcs, trackable_obj=None
)

From RESNET50 image classifier to any object detector

Hello Stack Overflow!
I am looking to use a resnet50 face classification model to transform it in a ssd, yolo or efficientDet. Is this even possible? Basically I am looking to use a trained model that detects single classes in an image to detect more than a single class in an image. To partition an input image, detect the objects(faces) in the given image based on my resnet50 classification model, where I give the yolo my resnet classification model as parameter.
Thanks in advance!

Can Yolo-V3 trained model be converted to TensorFlow model?

I have trained my model of doors in yolo-v3 but now I need it in TensorFlow-Lite. But, I am facing a problem, that is, if I want to train my model for tensorflow, I need annotation file in ".csv" or ".xml" but the ones I have are "*.txt". I did found a software to create annotation files manually from drawing rectangles in pictures but I can not do that for thousands of images due to time shortage.
Can anyone guide me how to handle such situation?
I have followed the following link but the resulted model did not work.
https://medium.com/analytics-vidhya/yolov3-to-tensorflow-lite-conversion-4602cec5c239
i think it will be good to train tensorflow implementation on your data , then converting tensrflow model to tflite should be easy
here is yolov3 in tf : https://github.com/YunYang1994/tensorflow-yolov3
then use official tensorflow codes to convert to tflite : https://www.tensorflow.org/lite/convert

Convert TFLite (TensorFlow) to MLModel (Apple)

I'm trying to convert TFLite Face Mesh model to MLModel (Apple).
TFLite model description:
https://drive.google.com/file/d/1VFC_wIpw4O7xBOiTgUldl79d9LA-LsnA/view
TFLite actual .tflite file:
https://github.com/google/mediapipe/blob/master/mediapipe/models/face_landmark.tflite
Looking at CoreMLTools provided by Apple (https://coremltools.readme.io/docs/introductory-quickstart) seems like it's possible, but all the samples codes demonstrate conversation from Keras and not from TFLite (although it's clearly supported):
How does one convert TFLite model to MLModel model?
As far as I know, there is no direct conversion from TFLite to Core ML. Someone could create such a converter but apparently no one has.
Two options:
Do it yourself. There is a Python API to read the TFLite file (flatbuffers) and an API to write Core ML files (NeuralNetworkBuilder in coremltools). Go through the layers of the TFLite model one-by-one, and add them to the NeuralNetworkBuilder, then save as a .mlmodel file.
Let TFLite do this for you. When you use the CoreMLDelegate in TFLite, it actually performs the model conversion on-the-fly and saves a .mlmodel file (or the compiled version, .mlmodelc). Then it uses Core ML to run this model. You can write some code to load the model with TFLite using the CoreMLDelegate, then grab the .mlmodel file that this created from the app bundle and use that.

How to estimate poses by tensorflow posenet

I've downloaded the tflite model from https://www.tensorflow.org/lite/models/pose_estimation/overview and I want to use it to estimate poses in images on my laptop with python, how to load the model and use it to do this?

Categories