WEBVTT

00:00.160 --> 00:06.200
The last function we need to create in this file is parse classification output.

00:06.320 --> 00:12.720
So here create private function parse classification output.

00:12.760 --> 00:15.120
It takes one parameter.

00:15.240 --> 00:16.760
Output buffer.

00:16.920 --> 00:19.560
It's of type tensor buffer.

00:19.560 --> 00:24.440
It returns a list of detection result class.

00:24.440 --> 00:29.280
Here start with val results equals to mutable.

00:29.400 --> 00:32.720
List of detection result.

00:32.720 --> 00:39.640
Also val output array equals to output buffer dot float array.

00:39.680 --> 00:46.320
Now I want from you to focus with me because there is a very important note here.

00:46.520 --> 00:48.080
We should pay attention to it.

00:48.120 --> 00:55.680
We're going to process classification model outputs and convert them into detection results.

00:55.680 --> 01:04.320
If you remember we stored the returning result of this parse classification output into the variable

01:04.320 --> 01:08.200
results and pass it to the listener on results method.

01:08.320 --> 01:17.200
And if you pay attention, the list of detection result is the returning type of the parse classification

01:17.240 --> 01:18.240
output function.

01:18.280 --> 01:22.360
Okay, now let's start to start the processing.

01:22.400 --> 01:34.120
For I in output array dot indices, if I less than labels size what we need to do.

01:34.280 --> 01:43.160
We need to start with val confidence equals to output array at index I.

01:43.360 --> 01:51.560
Then if the confidence greater than 0.5 f we need to add it to the results.

01:51.600 --> 01:54.960
Let me explain what we are doing here.

01:55.000 --> 02:00.370
As you know we are iterating through each element in the output array.

02:00.730 --> 02:07.170
Each element represents the confidence probability for a specific class.

02:07.210 --> 02:08.690
Okay, it's very simple.

02:08.690 --> 02:10.490
We are iterating over this array.

02:10.570 --> 02:12.250
Bounds checking.

02:12.410 --> 02:18.890
We are checking here if the labels dot size is is is accessible.

02:18.890 --> 02:27.930
And we ensure that we don't access beyond the available labels preventing index out of bounds exception.

02:27.970 --> 02:31.370
It's normal to now everything is normal.

02:31.570 --> 02:33.170
The val confidence.

02:33.170 --> 02:41.050
The output array at index I extract the confidence score of class at index I.

02:41.410 --> 02:50.450
We need to get the confidence at index I only processes classifications with 50% confidence.

02:50.650 --> 02:55.330
This filters out weak or unreliable predictions.

02:55.330 --> 03:00.850
So if there is a detection with 40% like a hard disk.

03:00.890 --> 03:02.170
We don't need it.

03:02.210 --> 03:08.290
We get classifications only higher than 50%.

03:08.290 --> 03:10.770
So this is the mean of it.

03:10.810 --> 03:11.170
Okay.

03:11.210 --> 03:12.050
It's very simple.

03:12.050 --> 03:19.570
If you need 60% higher 70% detection confidence, you can increase this number.

03:19.570 --> 03:20.250
For now.

03:20.290 --> 03:21.930
Keep it 50%.

03:21.970 --> 03:22.730
It's good.

03:22.770 --> 03:23.250
Okay.

03:23.650 --> 03:26.490
Now for classification models.

03:26.490 --> 03:29.410
We don't have bounding boxes.

03:29.410 --> 03:34.290
We'll create a dummy bounding box that covers the whole image.

03:34.290 --> 03:37.650
So for that starting with results dot add.

03:37.690 --> 03:41.170
And here set a detection result.

03:41.170 --> 03:47.450
Set the labels at label index confidence confidence and rect at rect f.

03:47.570 --> 03:50.290
Here let me draw this rect f.

03:50.490 --> 04:02.450
The left bound is for example zero f the left, the top 0F1, f right, and one f, but okay.

04:02.490 --> 04:06.370
This is a normalized coordinates of this results.

04:06.410 --> 04:11.050
The label class name from labels at index I.

04:11.090 --> 04:16.570
Confidence probability score from 0 to 1.0.

04:16.610 --> 04:25.850
So probability zero less than probability or confidence and one point that bounding box dummy rectangle

04:26.730 --> 04:32.170
covering the entire image okay so here dummy rectangle.

04:32.170 --> 04:38.370
By the way if we run the application and if there is any errors, any logical or drawing errors, we

04:38.370 --> 04:40.810
can modify those later on.

04:40.810 --> 04:41.290
Okay.

04:41.530 --> 04:45.010
Dummy rectangle covering entire image.

04:45.010 --> 04:48.770
We can replace it later on with with smaller okay.

04:48.970 --> 05:00.170
If the model detects hard disk with 0.8 confidence, it will throw it if the model detects like AirPods

05:00.450 --> 05:02.410
with confidence 0.3.

05:02.450 --> 05:03.970
It will not draw anything.

05:04.010 --> 05:04.490
Okay.

05:04.690 --> 05:05.050
Okay.

05:05.090 --> 05:06.170
It's very simple.

05:06.290 --> 05:08.650
Now I want from you to focus with me.

05:08.810 --> 05:13.330
The results don't add if the model detects if the model.

05:13.330 --> 05:14.570
Let me show you.

05:14.570 --> 05:22.890
If the model detects a hard disk with 0.8% confidence.

05:23.010 --> 05:24.810
What we need to pass here.

05:24.850 --> 05:26.650
What we need to add to the results.

05:26.650 --> 05:29.410
We're going to add detection.

05:29.570 --> 05:33.530
Result label is hard disk.

05:33.770 --> 05:38.810
So if we go to the labels dot text here we get hard disk.

05:38.810 --> 05:42.210
So the model will copy this name.

05:42.210 --> 05:47.050
This label passed to the first parameter of the detection result.

05:47.290 --> 05:54.850
Then the confidence is 0.8 and the bounding box would be a rect f.

05:54.850 --> 05:57.130
For example 0.1.

05:57.330 --> 05:59.900
Here we are drawing 0.0.

06:00.020 --> 06:02.940
So let me add 0.1 like this.

06:02.940 --> 06:05.660
You can draw it like this example.

06:05.660 --> 06:07.540
It's very good okay.

06:07.780 --> 06:11.180
So this is the model detection.

06:11.380 --> 06:16.660
And the detection result object will be added to the results array.

06:16.860 --> 06:23.660
Now let me return this results by specifying here the returning result.

06:23.700 --> 06:27.660
Returning result is result list.

06:27.700 --> 06:28.180
Okay.

06:28.460 --> 06:31.900
We need to move it outside till here.

06:32.060 --> 06:34.020
Let me show you guys.

06:34.500 --> 06:34.900
Oops.

06:34.940 --> 06:37.620
Let me remove it after this.

06:37.660 --> 06:38.780
And here we go.

06:39.060 --> 06:41.100
We have an extra one.

06:41.100 --> 06:44.500
And this should be for the list okay.

06:44.540 --> 06:48.660
So let me move it up and here we go okay.

06:48.740 --> 06:54.140
This is our function pass classification output.
