WEBVTT

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

00:01.040 --> 00:03.080
I want from you to focus with me.

00:03.080 --> 00:10.400
Now we need to connect our TensorFlow model with our house price screen.

00:10.640 --> 00:11.720
Composable.

00:11.880 --> 00:15.320
To do that, we need to create a new Kotlin class.

00:15.480 --> 00:20.000
Name it as TF Lite Helper class.

00:20.120 --> 00:31.480
This class takes into the parameters a private val context type context and let's start creating the

00:31.640 --> 00:32.720
interpreter.

00:33.040 --> 00:36.360
So private var interpreter.

00:36.480 --> 00:38.400
It's of type interpreter.

00:38.960 --> 00:43.000
What's the role of interpreter and why we use it.

00:43.000 --> 00:47.720
The interpreter is the class that runs the model.

00:47.960 --> 00:52.720
Interpreter is the TensorFlow Lite engine and nullable.

00:52.760 --> 01:00.520
Because initialization is delayed, the model can't always be loaded immediately when the object is

01:00.520 --> 01:01.520
created.

01:01.520 --> 01:10.330
So we are using this line and nullable because you need a class level handle to the TensorFlow Lite

01:10.370 --> 01:16.170
model interpreter, but you can't initialize it immediately at declaration time.

01:16.330 --> 01:24.370
It also ensures that you can safely clean it up when the component lifecycle ends.

01:24.490 --> 01:33.330
Okay, so the interpreter is the engine of TensorFlow Lite, the class that runs the model.

01:33.370 --> 01:38.170
Okay, so this is the main function of TensorFlow interpreter.

01:38.210 --> 01:45.290
Now inside the init block we need to import the model and use it.

01:45.290 --> 01:52.290
So try val model buffer equals to load model file.

01:52.330 --> 02:00.530
This is the class that we need to create the sorry the uh the function that we need to create okay.

02:00.690 --> 02:08.060
Here specify the name of the model which is house price light.

02:08.100 --> 02:08.420
Okay.

02:08.460 --> 02:11.820
Please pay attention to the name of the model.

02:11.820 --> 02:18.700
It's case sensitive, so make sure that it matches exactly the model's name.

02:18.740 --> 02:23.580
Then we need to use interpreter and initialize it here.

02:23.580 --> 02:29.620
So you can see guys here we are initializing the interpreter and passing the model buffer.

02:29.660 --> 02:38.060
We can set a logcat look log dot v tag model loaded successfully.

02:38.220 --> 02:39.340
In the catch.

02:39.500 --> 02:48.420
You can use another log to see if there is any error failed to load the model okay, so here we passed

02:48.460 --> 02:57.660
inside the interpreter constructor the model buffer which is the house price model tflite file.

02:57.700 --> 03:04.260
Now let's create the load model file that returns the mapped byte.
