WEBVTT

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

00:01.080 --> 00:06.000
We finished this composable function box with detection overlay.

00:06.200 --> 00:10.200
Now let's create another package.

00:10.480 --> 00:12.680
Name it as helper.

00:12.680 --> 00:16.960
And this package contains a new Kotlin file.

00:17.000 --> 00:21.080
Name it as object detector helper.

00:21.120 --> 00:31.520
It's of type class taking into its constructor private file, context object and private val listener.

00:31.680 --> 00:34.080
It's of type detection listener.

00:34.200 --> 00:38.880
The interface that we created before Alt+ enter to import the context.

00:38.880 --> 00:45.920
And let's start defining the variables interpreter from TensorFlow library.

00:45.960 --> 00:50.360
Define it as null empty list private var.

00:50.720 --> 00:53.800
The input width and input height are zero.

00:54.120 --> 00:56.960
The interpreter is the TensorFlow.

00:57.000 --> 01:05.320
Lite object that loads and runs the Tflite model to make predictions.

01:05.320 --> 01:11.640
So we're going to use it to load this model that we've added before to our application.

01:11.640 --> 01:22.440
And here we are telling that this interpreter, it can hold either an actual interpreter object or a

01:22.480 --> 01:23.040
null.

01:23.280 --> 01:29.480
When you net, you are not initializing it or after being closed.

01:29.560 --> 01:38.520
Okay, so interpreter can be null or holding an object of type interpreter labels equals to string a

01:38.640 --> 01:41.360
list which holds all labels.

01:41.400 --> 01:41.920
Okay.

01:42.080 --> 01:46.800
In each block let me call the set up interpreter.

01:46.840 --> 01:49.840
This is the function that we're going to create here.

01:50.120 --> 01:54.280
So private function set up interpreter.

01:54.280 --> 01:57.680
And here we're going to load the model.

01:57.720 --> 02:06.400
As we learned before we need to use try and catch to load the models and handle any possible possibility

02:06.400 --> 02:07.320
of errors.

02:07.320 --> 02:20.070
And try here start with loading the model var model equals to Do file util dot load mapped file.

02:20.230 --> 02:27.190
This function has two parameters the context and the file path.

02:27.190 --> 02:32.390
The context is context, and the file path is the name of the model.

02:32.590 --> 02:34.110
What's the name of the model?

02:34.110 --> 02:39.350
It's called HDD underscore AirPods underscore model.

02:39.390 --> 02:49.070
So make sure that you type it well HDD AirPods model make sure that it matches correctly.

02:49.070 --> 02:56.830
The name of the file hdd_airpods_model.tf Lite okay.

02:56.990 --> 02:59.510
And it's highlighted by green.

02:59.510 --> 03:04.870
And it's um like referenced here and detected.

03:04.870 --> 03:06.750
So everything is working fine.

03:06.790 --> 03:15.310
Then we need to use the interpreter to pass the model to it's buffer byte buffer okay.

03:15.550 --> 03:21.750
So the first step is loading the memory the model from the assets into memory.
