WEBVTT

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

00:01.000 --> 00:05.240
We created the prepare image for model function.

00:05.440 --> 00:14.640
Now let's create the parts detection results function here under the previous function create function.

00:14.640 --> 00:17.960
Private function pass detection results.

00:17.960 --> 00:22.120
The returning type is a list of detection object.

00:22.280 --> 00:26.640
Start with val detected objects.

00:26.640 --> 00:29.960
It's a mutable list of detection object.

00:30.120 --> 00:40.560
Then val detection count equals to output number of detections at index zero.

00:40.800 --> 00:55.560
Output num detections at index 0.2, end dot course at most and get the maximum detection number.

00:55.600 --> 01:00.620
Maximum detection number which is Print ln.

01:00.860 --> 01:03.100
Number of detections.

01:03.340 --> 01:04.540
Detection count.

01:04.620 --> 01:12.260
This code extracts and limits the row detection results from the model output.

01:12.300 --> 01:20.580
Read detection count gets the number of valid detections from output detections.

01:20.700 --> 01:26.340
Output detection number array at index zero and apply safely.

01:26.620 --> 01:33.540
Limit ensures we don't need to exceed maximum detection number.

01:33.820 --> 01:43.260
The array bounds protection if we go up, this is included inside the companion object and set it to

01:43.460 --> 01:44.340
ten.

01:44.340 --> 01:47.780
So the maximum detection number is ten.

01:47.820 --> 01:50.300
You can specify it directly like this.

01:50.300 --> 01:55.100
But I prefer using the not not the hard coded.

01:55.380 --> 01:58.450
I prefer using the Variables.

01:58.490 --> 02:06.610
The initial results creates empty mutable list to store processed detections.

02:06.850 --> 02:11.490
This is the processed detections and debugging here.

02:11.530 --> 02:20.130
The printing the number of count for monitoring typically removed in production.

02:20.290 --> 02:22.930
This is our first step.

02:23.170 --> 02:24.770
Now we need that.

02:24.770 --> 02:30.290
The key points the bounds safe uses course at most.

02:30.330 --> 02:37.250
This is a new function that we introduced to prevent index out of bounds errors.

02:37.530 --> 02:40.170
So let me write this node down.

02:40.410 --> 02:47.330
The course at most prevents index out of bounds errors okay.

02:47.530 --> 02:54.130
This is the first step in converting row model outputs into usable detections objects.

02:54.170 --> 02:54.650
Okay.

02:54.890 --> 03:03.990
So in this in this function we are converting row model to detection object.

03:04.030 --> 03:16.790
Now for every detection for every integer I in zero until detection count what we need to do.

03:17.030 --> 03:24.910
We need to start with val score equals to output score.

03:25.230 --> 03:28.550
Get index zero at index I.

03:28.590 --> 03:39.550
This is the two dimensional array starting from row zero and index which is the the column at index

03:39.550 --> 03:40.350
I okay.

03:40.510 --> 03:45.310
What we need to do we need to filter by confidence.

03:45.310 --> 03:52.630
This is threshold we have if score less than parameters dot score threshold.

03:52.830 --> 04:01.500
So if we go to the score threshold As we said before, it's 0.6, meaning that every detected object

04:01.500 --> 04:13.180
with a score lower than 60%, it will be neglected, but higher every object out and and higher that

04:13.180 --> 04:14.100
has the.

04:14.140 --> 04:19.420
Any object has a score greater than 60%.

04:19.540 --> 04:26.060
Go and display a box around it and set it inside our detected objects.

04:26.180 --> 04:26.700
Okay.

04:27.140 --> 04:28.780
So here continue.

04:28.820 --> 04:33.740
Go and continue and make another iteration.

04:33.740 --> 04:40.660
If not, create a val label index output classes dot to integer.

04:40.780 --> 04:47.460
Then if the label index it's not in labels.

04:47.460 --> 04:51.060
Dot indices is what we need to do.

04:51.340 --> 04:53.820
We need to continue also.

04:53.840 --> 04:58.680
So here also we need to print or without using the print.

04:58.720 --> 05:02.120
We can make a log here but it's safe.

05:02.160 --> 05:12.800
Okay then remove this label index val label equals to labels at label index.

05:12.840 --> 05:17.000
Bounding box equals to output locations.

05:17.160 --> 05:23.080
This extracts the class, label and bounding box for each detection.

05:23.080 --> 05:32.160
Getting the label looks up the human readable class name using label index from output classes.

05:32.160 --> 05:38.160
If the label index equals to zero, label might be person.

05:38.160 --> 05:38.840
If we.

05:39.240 --> 05:50.400
If we notice that the SSD here MobileNet and we have the Coco database, we we can understand it better

05:50.400 --> 05:54.990
for from the labels and get bounding box here.

05:55.030 --> 06:00.550
Retrieving coordinates from output locations.

06:00.790 --> 06:08.630
It's a 2D array for a, typically a y minimum x minimum, y maximum x maximum.

06:08.750 --> 06:11.270
As normalized values between 0 and 1.

06:11.270 --> 06:22.030
If we go up, as I told you in the previous video, we talked about the shape here y minimum y x maximum

06:22.230 --> 06:25.670
or x minimum, y maximum and x maximum.

06:25.910 --> 06:28.150
This is the output array.

06:28.470 --> 06:33.390
So if we scroll down here we have the bounding box okay.

06:33.550 --> 06:35.310
It's very simple.

06:35.350 --> 06:38.950
Now let's continue with the SSD mobile.

06:38.950 --> 06:46.630
Net model that returning coordinates in the form that we have and draw the rectangle.
