Predicts bounding box coordinates directly without using box generator. By directly predicting bounding boxes, accurate box coordinates can be obtained.
for reg_layer, conf_layer in zip(self.regression_headers, self.classification_headers):
locs = reg_layer(locs) # (B, 4, H, W)
confs = conf_layer(confs) # (B, num_classes, H, W)The PostProcessor class handles post-processing for the bounding boxes and scores predicted by the model.
-
Inputs:
locs: List of bounding box coordinatesconfs: List of class confidence scores
-
Outputs:
result_boxes: Final selected bounding boxesresult_labels: Class labels of the bounding boxesresult_scores: Confidence scores of the bounding boxesresult_confs: Raw confidence values
-
Functionality:
- Applies softmax to select the highest-scoring class
- Removes low-score predictions based on
score_threshold - Uses Non-Maximum Suppression (NMS) to eliminate redundant boxes
The SSD class consists of the following major components:
-
Backbone: CNN network for feature map extraction
-
Extras: Additional layers to detect objects of different sizes
-
Classification Headers: Predict class scores
-
Regression Headers: Predict bounding box coordinates
-
PostProcessor: Filters and processes detection results
-
Inputs:
x: Input image tensor
-
Outputs:
result_boxes: Bounding box coordinatesresult_labels: Class labelsresult_scores: Scores of detected objectsresult_confs: Raw confidence values
The loss function used for training the SSD model.
-
Loss Function Components:
SmoothL1Loss: Bounding box regression lossCrossEntropyLoss: Classification loss
-
Inputs:
result_boxes: Predicted bounding boxesresult_confs: Predicted class confidence scorestarget_locs: Ground truth bounding boxestarget_labels: Ground truth class labels
-
Outputs:
total_loss: Total loss (regression loss + classification loss)train_acc: Training accuracy
-
Hungarian Matching for Alignment:
- Matches predicted and ground truth bounding boxes before computing loss
python train_ssd.py --arch mobilenetv3_ssd --datapath dataset_coco --epochs 10 --batch-size 5 --lr 0.001 --save ssd.pt