WEBVTT

00:00.080 --> 00:00.840
Welcome back.

00:00.840 --> 00:07.160
If you remember from the previous videos, we have our linear relationship price equals to three times

00:07.200 --> 00:09.040
size plus two plus noise.

00:09.320 --> 00:14.840
We give the model the size in square feet which is the input layer.

00:14.840 --> 00:17.720
We have only one number, one input.

00:18.040 --> 00:26.160
That dense layer will start learning w and B, which are the slope and the intercept respectively.

00:26.600 --> 00:33.160
Then in the output layer we get the price and calculate the price according to the learned equation.

00:33.160 --> 00:35.520
We take size.

00:35.520 --> 00:38.360
We take one number as input.

00:38.400 --> 00:42.480
We get price which is another number.

00:42.640 --> 00:44.560
So the input is one number.

00:44.560 --> 00:47.120
The output is one number.

00:47.160 --> 00:48.840
This is very important.

00:48.840 --> 00:53.880
You should understand what are the model input and output.

00:53.920 --> 00:58.440
Back to Android Studio we created this load model file.

00:58.600 --> 01:04.890
Now let's create the function that will do the Their prediction.

01:05.130 --> 01:11.930
So here function predict how many variables we need to pass.

01:11.970 --> 01:15.770
We need to pass only one variable as an input.

01:15.770 --> 01:23.410
So here the size input which is a float and how many outputs we get.

01:23.450 --> 01:26.610
We need to return only one float.

01:26.650 --> 01:27.210
Okay.

01:27.370 --> 01:30.610
So here we need to return a float.

01:30.650 --> 01:32.210
Let's start with val.

01:32.450 --> 01:45.250
Input size equals to array of float array of and we pass the size input here the shape to the array

01:45.250 --> 01:47.370
or shape to the array.

01:47.610 --> 01:49.090
Let me move it to here.

01:49.130 --> 01:51.890
Set the shape one one also.

01:52.090 --> 01:54.730
Val output price.

01:54.770 --> 01:59.010
Array of float array of zero.

01:59.170 --> 02:02.170
Also the shape is one one.

02:02.210 --> 02:04.410
Please pay attention with me.

02:04.450 --> 02:10.740
TensorFlow Lite models expect multi-dimensional arrays or tensors.

02:10.860 --> 02:20.740
Even if your model takes a single number exactly like our situation, we only need to pass the size

02:20.740 --> 02:22.900
of the house as an input.

02:22.900 --> 02:25.060
So we have only one single number.

02:25.220 --> 02:28.060
It must be wrapped in arrays.

02:28.100 --> 02:33.580
Float array of this function gives us a 1D array.

02:33.780 --> 02:43.540
We wrap the size input into 1D array, and in order to transform this 1D array into 2D array, we use

02:43.580 --> 02:51.540
float array of array of float array of x into transformed into 2D array.

02:51.740 --> 02:54.420
So the size input is float.

02:54.660 --> 02:58.020
We when we put it with float array of.

02:58.060 --> 03:03.100
This will transform our data our float into 1D array.

03:03.620 --> 03:08.860
If we wrapped inside array of, we get a 2D array.

03:09.100 --> 03:12.070
So guys this is a very important step.

03:12.070 --> 03:14.310
You should pay attention to it.

03:14.510 --> 03:19.670
We need to transform our float into a tensor.

03:19.710 --> 03:23.550
A tensor is a 2D array or multi-dimensional arrays.

03:23.590 --> 03:30.830
Okay so again guys the size input is float float array of is 1D array.

03:31.070 --> 03:41.270
Transforming the float into 1D array and array of transforming it into a 2D array similar to the output

03:41.270 --> 03:41.990
price.

03:42.030 --> 03:48.470
Okay, so here we are preparing an empty output container for TensorFlow Lite to fill in.

03:48.670 --> 03:58.270
It's initialized with zero f, but will be overwritten and shape one one again one prediction result

03:58.270 --> 03:59.750
for one input.

03:59.750 --> 04:05.310
So the shape one prediction result for one input.

04:05.350 --> 04:08.550
Then we need to run the interpreter.

04:08.550 --> 04:11.150
So run inference with the input data.

04:11.190 --> 04:17.120
Start with a return Try interpreter dot run.

04:17.160 --> 04:22.800
Pass the input size and the output price.

04:22.800 --> 04:27.560
Set the output price zero zero and the Logcat.

04:27.600 --> 04:34.680
Here if we have an error log ve failed to predict the interpreter dot run.

04:34.720 --> 04:42.640
Here we are using the interpreter that we initialized before and run it with the model.

04:42.640 --> 04:49.880
So here we are running the model and passing the input and the output the input input size.

04:49.880 --> 04:52.080
The output is the output price.

04:52.240 --> 05:01.760
Since interpreter is nullable, the safe call exclamation mark dot avoids crashes if it is not initialized.

05:01.760 --> 05:11.800
And here after inference, the result is stored inside the output, returning the prediction result.

05:11.800 --> 05:21.410
First row first column of the 2D array stores result in the first and only element of the 2D array,

05:21.410 --> 05:23.810
and this returns a float.

05:23.810 --> 05:31.210
And here we have error handling in case if there is any error, if anything goes wrong, it logs the

05:31.210 --> 05:33.570
error and returns null.

05:33.610 --> 05:44.170
In short, this function takes a single number which is the size input feeds it into your TensorFlow

05:44.410 --> 05:50.290
Lite TensorFlow Lite model and returns the predicted number.

05:50.410 --> 05:54.650
It's a wrapper that shapes the input correctly.

05:54.650 --> 05:58.130
Like as we learned here, size is a float.

05:58.290 --> 06:01.330
We transformed it to a 1D array.

06:01.370 --> 06:11.010
Then we transformed it to 2D array, runs the inference and extract the and returns the result safety,

06:11.170 --> 06:15.010
storing it into the first element of the 2D array.
