Congratulations guys!
We exported our model and load it successfully in TensorFlow.
Now let's export models as TF Lite for Android.
So we're going to use this model to make predictions in Android Studio.
I can't go and paste this model linear regression export or the Savedmodel file in Android Studio because
TensorFlow will not work.
Also, Android Studio will not recognize those files and those models.
We need a specific extension which is the dot light for Android.
Okay, so here let me start converting the current model to TF Lite.
Here we have the loaded model and the model that we build it together.
So let me start exporting the model that we've built together and then move to the loaded model.
Okay.
So here converter equals to tf.light.tf light converter from Keras model and pass the model and not
the current model or the uh, or the tested model or the loaded model.
Okay, so pass the model because this is used to convert our model, our trained model to TF Lite extension,
then we need to convert the model TF Lite model dot equals to converter dot convert.
Also this is the converter.
So we we did the conversion.
We need to save the file.
So I need to get the output file.
So here I need to get an output tf.tf lite file.
For that I need to make the TF lite model path house price model.tf lite extension and with open TF
lite model path we passed here WB as f f dot write tf lite model.
Let me explain what we've done here.
The TF Lite format optimized for mobile and edge devices like microcontrollers.
And here we use the TF Lite converter from Keras model to do this conversion.
So here here we are creating a converter that understands your Keras model structure.
The converter analyzes your model architecture, examines layers, weights and connections, prepares
for optimization and conversion.
By this step, the converter understands the input one feature house size.
The operation dense layer with one neuron output is one value house price and the parameters are weight
and bias.
Then we use TF Lite modal converter dot convert.
The purpose is to perform the actual conversion to two light format.
What happens during conversion optimizes operations for mobile devices.
Quantizers or Quantizers weights, if specified, creates a flat buffer format.
Tflite reduces model size and improves performance.
The last step is to save the tflite file.
WB writes in binary model and in binary mode.
The binary format not human readable, optimized for fast loading.
So WB write in binary mode required for tflite and binary format is not human readable.
Here Tflite model path.
This is the path and the name and WB write in binary.
Go and write it in order to create this file.
So let's run the cell and here we go.
It's executed.
Go open the folders and.
Congratulations, guys.
We have this model called House price model dot flight.
Click download.
And in the next videos we're going to use this model with Android Studio.
So this is the file that we're going to move it to Android Studio Assets folder.
One last thing we need to mention here converting current model to Tflite.
But what about converting the export the loaded model.
So here, as we learned before, we loaded a model from uh, from uh, a file or a folder, how to export
it as Tflite.
It's very simple.
So here as we did in the in the previous conversion, I'll copy this and paste it here.
Converter Tflite dot Tflite converter from Keras model.
It's not from Keras model, it's from saved model.
Okay.
And you pass the name of the model.
For example linear regression.
Export the name of the file a folder that we exported.
And we need to load and convert it.
And then TF Lite model equals to converter dot convert.
Similar to what we've done before with open.
Also go and write it in binary.
Name it as TF Lite.
I'll name it as for example the loaded model.tf Lite.
Okay, it's very simple.
And the print the conversion is done.
Let's run.
And here we go.
Let me check.
And the loaded model.tf Lite is being created.
Okay guys what we've done here we converted our model our model that we learned before our loaded model.
So here are the previous videos.
We worked on a model named as model and we exported to a TF Lite for Android using from Keras model
function.
Also, we learned how to load the exported models, how to load the models from external and and maybe
other developers created.
Um, we, we exported the model and we loaded and we load it here in order to make the conversion.
And we succeeded in converting any loaded model folder to TF Lite.
So this is our current model.
This is our current model that we worked on on the on the previous videos.
And this is the loaded model that we exported from an external.