Load the training data for vehicle detection into the workspace.
Specify the directory in which training samples are stored. Add full path to the file names in training data.
Create an image datastore using the files from the table.
Create a box label datastore using the label columns from the table.
Combine the datastores.
Load a preinitialized SSD object detection network.
lgraph =
LayerGraph with properties:
Layers: [23×1 nnet.cnn.layer.Layer]
Connections: [24×2 table]
InputNames: {'input'}
OutputNames: {'focalLoss' 'anchorBoxRegression'}
Inspect the layers in the SSD network and their properties. You can also create the SSD network by following the steps given in Create SSD Object Detection Network.
ans =
23x1 Layer array with layers:
1 'input' Image Input 300x300x3 images
2 'conv_1' Convolution 16 3x3 convolutions with stride [1 1] and padding [1 1 1 1]
3 'relu_1' ReLU ReLU
4 'maxpool1' Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0]
5 'conv_2' Convolution 32 3x3 convolutions with stride [1 1] and padding [1 1 1 1]
6 'relu_2' ReLU ReLU
7 'maxpool2' Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0]
8 'conv_3' Convolution 64 3x3 convolutions with stride [1 1] and padding [1 1 1 1]
9 'relu_3' ReLU ReLU
10 'maxpool3' Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0]
11 'conv_4' Convolution 128 3x3 convolutions with stride [1 1] and padding [1 1 1 1]
12 'relu_4' ReLU ReLU
13 'confmerge' SSD Merge Layer. SSD Merge Layer.
14 'locmerge' SSD Merge Layer. SSD Merge Layer.
15 'relu_4_anchorbox' Anchor Box Layer. Anchor Box Layer.
16 'relu_4_mbox_conf' Convolution 8 3x3x128 convolutions with stride [1 1] and padding [1 1 1 1]
17 'relu_4_mbox_loc' Convolution 16 3x3x128 convolutions with stride [1 1] and padding [1 1 1 1]
18 'relu_3_anchorbox' Anchor Box Layer. Anchor Box Layer.
19 'relu_3_mbox_conf' Convolution 12 3x3x64 convolutions with stride [1 1] and padding [1 1 1 1]
20 'relu_3_mbox_loc' Convolution 24 3x3x64 convolutions with stride [1 1] and padding [1 1 1 1]
21 'anchorBoxSoftmax' Softmax softmax
22 'focalLoss' Focal Loss Layer. Focal Loss Layer.
23 'anchorBoxRegression' Box Regression Output smooth-l1 loss
Configure the network training options.
Train the SSD network.
*************************************************************************
Training an SSD Object Detector for the following object classes:
* vehicle
Training on single GPU.
|========================================================================================|
| Epoch | Iteration | Time Elapsed | Mini-batch | Mini-batch | Base Learning |
| | | (hh:mm:ss) | RMSE | Loss | Rate |
|========================================================================================|
| 1 | 1 | 00:00:04 | 250.16 | 197.6 | 5.0000e-05 |
| 4 | 10 | 00:00:23 | 26.19 | 20.7 | 5.0000e-05 |
| 7 | 20 | 00:00:42 | 8.35 | 5.4 | 5.0000e-05 |
| 10 | 30 | 00:01:01 | 3.02 | 2.3 | 5.0000e-05 |
| 14 | 40 | 00:01:25 | 1.82 | 1.0 | 5.0000e-05 |
| 17 | 50 | 00:01:44 | 1.20 | 0.7 | 5.0000e-05 |
| 20 | 60 | 00:02:02 | 1.39 | 0.8 | 5.0000e-05 |
| 24 | 70 | 00:02:26 | 1.17 | 0.6 | 5.0000e-05 |
| 27 | 80 | 00:02:44 | 1.07 | 0.6 | 5.0000e-05 |
| 30 | 90 | 00:03:03 | 1.15 | 0.6 | 5.0000e-05 |
| 34 | 100 | 00:03:27 | 1.02 | 0.5 | 5.0000e-05 |
| 37 | 110 | 00:03:46 | 1.20 | 0.6 | 5.0000e-05 |
| 40 | 120 | 00:04:04 | 1.12 | 0.6 | 5.0000e-05 |
| 44 | 130 | 00:04:29 | 1.16 | 0.6 | 5.0000e-05 |
| 47 | 140 | 00:04:49 | 1.19 | 0.6 | 5.0000e-05 |
| 50 | 150 | 00:05:09 | 1.08 | 0.6 | 5.0000e-05 |
|========================================================================================|
Detector training complete.
*************************************************************************
Inspect the properties of the detector.
detector =
ssdObjectDetector with properties:
ModelName: 'vehicle'
Network: [1×1 DAGNetwork]
ClassNames: {'vehicle' 'Background'}
You can verify the training accuracy by inspecting the training loss for each iteration.
Test the SSD detector on a test image.
Run the SSD object detector on the image for vehicle detection.
Display the detection results.