WEBVTT

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

00:01.080 --> 00:05.480
We loaded the model and converted it as a byte buffer.

00:05.680 --> 00:08.880
Now let's load the labels.

00:09.080 --> 00:15.960
So, as I told you before, we need to load the model and the labels here.

00:16.000 --> 00:16.480
Okay.

00:16.800 --> 00:20.120
So for that create a new function.

00:20.120 --> 00:23.080
Name it as load labels.

00:23.080 --> 00:30.840
And this function takes a file name as a string returning a list of string.

00:31.120 --> 00:33.520
And this will return.

00:33.680 --> 00:41.400
Try val input stream equals to context dot assets dot.

00:41.880 --> 00:43.440
Open the file name.

00:43.680 --> 00:47.400
Then we need a buffered reader.

00:47.520 --> 00:54.240
So val buffered reader equals to the input stream dot bufferedreader.

00:54.240 --> 00:59.000
Or we can make it like this buffered reader.

00:59.160 --> 01:07.180
We need to create an input stream reader, input stream reader and pass the input stream.

01:07.260 --> 01:11.140
Then use the Bufferedreader dot read lines.

01:11.260 --> 01:19.940
This code will read a text file from assets, which is this cocoa database data set underscore labels

01:19.940 --> 01:27.300
dot txt file and returns it content as a list of strings.

01:27.380 --> 01:30.060
We need to return them as lines.

01:30.060 --> 01:36.300
So here if we open it we need to return them as lines.

01:36.460 --> 01:45.260
So for this purpose we used Inputstream Bufferedreader and we pass the input stream reader.

01:45.420 --> 01:55.260
This will read a text file from assets line by line, returning a list of string where each element

01:55.260 --> 02:03.350
is one line of the file and automatically handles character encoding and line breaks.

02:03.590 --> 02:12.910
The input stream context ascites dot open appends the file as a row input stream from the apps assets

02:12.910 --> 02:13.470
folder.

02:13.470 --> 02:19.670
Returns a basic byte stream without any character encoding and decoding.

02:19.870 --> 02:26.190
The input stream reader converts the raw byte stream into a character stream.

02:26.390 --> 02:28.430
Handles character encoding.

02:28.430 --> 02:37.230
Uses platforms the default encoding if not specified, and can specify encoding explicitly like UTF

02:37.430 --> 02:45.390
eight here, so I can specify it here, like use the dash eight.

02:45.430 --> 02:51.270
Okay, but I don't want from for this example because it's very simple.

02:51.550 --> 03:02.010
And the byte buffer or buffered reader wraps the input stream reader to provide buffering improves performance

03:02.010 --> 03:10.610
by reading large chunks at once, and provides convenient line reading methods and read lines.

03:10.730 --> 03:17.010
Here, the method reads all lines from the file into a list of strings.

03:17.170 --> 03:22.450
Each line is stripped of line termination character.

03:22.610 --> 03:28.570
The reader is automatically closed after reading if using use block.

03:28.810 --> 03:36.650
Okay, this is how we read a text file from assets and returns its content as a list of strings.

03:36.690 --> 03:48.330
Let me surround this with catch block with E for exception and log the loaded labels okay and return

03:48.330 --> 03:51.610
an empty list in case of failure.
