WEBVTT

00:00.080 --> 00:01.560
Congratulations guys!

00:01.560 --> 00:06.160
We exported our model and load it successfully in TensorFlow.

00:06.280 --> 00:11.520
Now let's export models as TF Lite for Android.

00:11.520 --> 00:17.280
So we're going to use this model to make predictions in Android Studio.

00:17.440 --> 00:27.320
I can't go and paste this model linear regression export or the Savedmodel file in Android Studio because

00:27.680 --> 00:30.000
TensorFlow will not work.

00:30.000 --> 00:34.320
Also, Android Studio will not recognize those files and those models.

00:34.440 --> 00:41.840
We need a specific extension which is the dot light for Android.

00:41.880 --> 00:47.320
Okay, so here let me start converting the current model to TF Lite.

00:47.400 --> 00:54.040
Here we have the loaded model and the model that we build it together.

00:54.040 --> 01:02.600
So let me start exporting the model that we've built together and then move to the loaded model.

01:02.640 --> 01:03.160
Okay.

01:03.350 --> 01:13.550
So here converter equals to tf.light.tf light converter from Keras model and pass the model and not

01:13.550 --> 01:19.430
the current model or the uh, or the tested model or the loaded model.

01:19.470 --> 01:31.110
Okay, so pass the model because this is used to convert our model, our trained model to TF Lite extension,

01:31.110 --> 01:39.630
then we need to convert the model TF Lite model dot equals to converter dot convert.

01:39.910 --> 01:42.190
Also this is the converter.

01:42.350 --> 01:44.750
So we we did the conversion.

01:44.750 --> 01:47.070
We need to save the file.

01:47.070 --> 01:49.710
So I need to get the output file.

01:49.710 --> 01:56.190
So here I need to get an output tf.tf lite file.

01:56.190 --> 02:06.310
For that I need to make the TF lite model path house price model.tf lite extension and with open TF

02:06.310 --> 02:13.350
lite model path we passed here WB as f f dot write tf lite model.

02:13.390 --> 02:16.030
Let me explain what we've done here.

02:16.150 --> 02:22.830
The TF Lite format optimized for mobile and edge devices like microcontrollers.

02:22.950 --> 02:29.790
And here we use the TF Lite converter from Keras model to do this conversion.

02:29.790 --> 02:37.750
So here here we are creating a converter that understands your Keras model structure.

02:37.870 --> 02:46.390
The converter analyzes your model architecture, examines layers, weights and connections, prepares

02:46.550 --> 02:49.470
for optimization and conversion.

02:49.470 --> 02:56.390
By this step, the converter understands the input one feature house size.

02:56.430 --> 03:04.910
The operation dense layer with one neuron output is one value house price and the parameters are weight

03:04.910 --> 03:06.030
and bias.

03:06.030 --> 03:11.220
Then we use TF Lite modal converter dot convert.

03:11.260 --> 03:17.060
The purpose is to perform the actual conversion to two light format.

03:17.100 --> 03:22.580
What happens during conversion optimizes operations for mobile devices.

03:22.620 --> 03:29.620
Quantizers or Quantizers weights, if specified, creates a flat buffer format.

03:29.660 --> 03:34.660
Tflite reduces model size and improves performance.

03:34.780 --> 03:38.620
The last step is to save the tflite file.

03:38.660 --> 03:44.620
WB writes in binary model and in binary mode.

03:44.660 --> 03:49.820
The binary format not human readable, optimized for fast loading.

03:49.820 --> 03:57.580
So WB write in binary mode required for tflite and binary format is not human readable.

03:57.620 --> 04:00.300
Here Tflite model path.

04:00.340 --> 04:04.860
This is the path and the name and WB write in binary.

04:04.900 --> 04:08.260
Go and write it in order to create this file.

04:08.380 --> 04:11.980
So let's run the cell and here we go.

04:12.380 --> 04:13.620
It's executed.

04:13.620 --> 04:16.380
Go open the folders and.

04:16.380 --> 04:18.020
Congratulations, guys.

04:18.020 --> 04:23.980
We have this model called House price model dot flight.

04:24.020 --> 04:25.700
Click download.

04:25.860 --> 04:31.340
And in the next videos we're going to use this model with Android Studio.

04:31.420 --> 04:36.620
So this is the file that we're going to move it to Android Studio Assets folder.

04:36.660 --> 04:41.700
One last thing we need to mention here converting current model to Tflite.

04:41.860 --> 04:46.620
But what about converting the export the loaded model.

04:46.620 --> 04:55.860
So here, as we learned before, we loaded a model from uh, from uh, a file or a folder, how to export

04:55.860 --> 04:57.460
it as Tflite.

04:57.460 --> 04:58.860
It's very simple.

04:58.860 --> 05:07.500
So here as we did in the in the previous conversion, I'll copy this and paste it here.

05:07.700 --> 05:13.730
Converter Tflite dot Tflite converter from Keras model.

05:13.730 --> 05:18.650
It's not from Keras model, it's from saved model.

05:18.690 --> 05:19.210
Okay.

05:19.530 --> 05:22.610
And you pass the name of the model.

05:22.610 --> 05:25.090
For example linear regression.

05:25.370 --> 05:30.250
Export the name of the file a folder that we exported.

05:30.450 --> 05:33.090
And we need to load and convert it.

05:33.090 --> 05:37.610
And then TF Lite model equals to converter dot convert.

05:37.610 --> 05:41.210
Similar to what we've done before with open.

05:41.330 --> 05:43.730
Also go and write it in binary.

05:43.850 --> 05:46.810
Name it as TF Lite.

05:47.050 --> 05:53.210
I'll name it as for example the loaded model.tf Lite.

05:53.250 --> 05:55.330
Okay, it's very simple.

05:55.490 --> 05:58.690
And the print the conversion is done.

05:58.690 --> 05:59.970
Let's run.

05:59.970 --> 06:01.170
And here we go.

06:01.370 --> 06:02.370
Let me check.

06:02.490 --> 06:07.290
And the loaded model.tf Lite is being created.

06:07.530 --> 06:17.290
Okay guys what we've done here we converted our model our model that we learned before our loaded model.

06:17.290 --> 06:19.850
So here are the previous videos.

06:19.850 --> 06:32.050
We worked on a model named as model and we exported to a TF Lite for Android using from Keras model

06:32.170 --> 06:32.970
function.

06:32.970 --> 06:42.650
Also, we learned how to load the exported models, how to load the models from external and and maybe

06:42.650 --> 06:44.890
other developers created.

06:45.090 --> 06:55.290
Um, we, we exported the model and we loaded and we load it here in order to make the conversion.

06:55.290 --> 07:00.410
And we succeeded in converting any loaded model folder to TF Lite.

07:00.410 --> 07:02.650
So this is our current model.

07:02.650 --> 07:08.690
This is our current model that we worked on on the on the previous videos.

07:08.690 --> 07:14.090
And this is the loaded model that we exported from an external.
