Skip to content

Image understanding, generation, and 3D reconstruction · Object detection · VIS004 · Architecture

Single Shot MultiBox Detector (SSD)

SSD performs dense one-stage detection from feature maps at multiple resolutions. Default boxes of varying scales and aspect ratios provide localization references, avoiding a separate region-proposal stage.

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

SSD performs dense one-stage detection from feature maps at multiple resolutions. Default boxes of varying scales and aspect ratios provide localization references, avoiding a separate region-proposal stage.

Question / hypotheses

Can multiscale default-box predictions detect the relevant object sizes in a single network pass? This is a modeling/evaluation question, not a formal null-hypothesis test.

Architecture / computational structure

A convolutional backbone and extra feature layers produce multi-resolution maps. Prediction heads emit class scores and offsets for each default box, with matching and hard-negative mining used in training and suppression during inference.

Assumptions

Tiny objects may be poorly represented at coarse scales. Dense negatives dominate without appropriate sampling; images with no positives require a defined loss normalization and mining policy. A default-box score is not automatically calibrated object probability.

Formula / computational definition

L=N+−1(Lconf+αLloc)L=N_+^{-1}(L_{conf}+\alpha L_{loc}), where N+N_+ is matched positive-box count, confidence uses class cross-entropy and localization uses Smooth L1 offsets. Hard-negative mining retains high-loss unmatched defaults relative to the positive count.

Parameters and notation

Notation: Here N_+ counts positive default-box matches, L_conf is the selected classification-loss sum and L_loc the positive localization-loss sum. Alpha controls their balance. The original objective defines zero loss when N_+=0; implementations must handle that case without division by zero.

Learned or estimated: Backbone, additional feature layers and class/localization prediction filters.

Hyperparameters and effects: Default-box scales/ratios, feature-map resolutions, matching IoU, negative-to-positive ratio, input size and suppression thresholds. Defaults and feature strides determine coverage of object shapes and scales.

Fitting, fine-tuning, and adaptation

Fit target heads with pretrained feature extraction, then unfreeze later layers at lower rates. When object sizes or image resolution change, adjust default boxes on training data and retrain compatible prediction heads. Recheck source categories and proposal coverage after adaptation; postprocessing threshold tuning belongs on validation images.

How to use and calibrate

Split by independent image source, scene, subject or capture sequence before augmentation; keep near-duplicate frames and crops in the same split. Measure AP by size/class, recall versus confidence threshold, dense-box matching statistics and measured device latency. Include postprocessing and resizing in timing comparisons.

Example application

Use a compact multi-scale one-stage detector for a fixed image resolution and well-characterized object-size distribution. This is a proposed use case, not a claim of validated performance on supplied real data.

Interpretation / pitfalls

Watch out

A training loss, confidence score or attention map is not a p-value or causal explanation. Confidence calibration, annotation quality and distribution-shift performance need separate assessment. A correct component calculation does not validate the full architecture, checkpoint or deployment pipeline.

Python and R code examples

Scope: SSD hard-negative mining on supplied classification losses; a 3:1 cap and positive-count normalization are shown, without default-box matching. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python: an audited SSD implementation. R: native torch prototypes or explicit Python bridge. The code illustrates hard-negative selection and positive-count normalization rather than a complete detector.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — SSD hard-negative mining on supplied classification losses; a 3:1 cap and positive-count normalization are shown, without default-box matching. Use the shared setup.

Shared setup for this chapter
import numpy as np
from itertools import permutations
def softmax(x):
    x=np.asarray(x,dtype=float)
    e=np.exp(x-x.max(axis=-1,keepdims=True))
    return e/e.sum(axis=-1,keepdims=True)
def bilinear(a,y,x):
    y=float(np.clip(y,0,a.shape[0]-1)); x=float(np.clip(x,0,a.shape[1]-1))
    y0=int(np.floor(y)); x0=int(np.floor(x))
    y1=min(y0+1,a.shape[0]-1); x1=min(x0+1,a.shape[1]-1)
    dy=y-y0; dx=x-x0
    return (1-dy)*((1-dx)*a[y0,x0]+dx*a[y0,x1])+dy*((1-dx)*a[y1,x0]+dx*a[y1,x1])
positive=np.array([True,False,False,True,False,False,False,False,False,False])
ce=np.array([.2,.9,.1,.3,.8,.4,.05,.7,.6,.2])
pos_n=positive.sum(); negative=np.flatnonzero(~positive)
keep=negative[np.argsort(ce[negative])[::-1][:3*pos_n]]
loc_sum=.7
loss=(ce[positive].sum()+ce[keep].sum()+loc_sum)/pos_n
assert len(keep)==6 and not positive[keep].any()
print('negative indices (zero-based):',keep,'normalized loss:',loss)
R

Component demo, not a trained model — SSD hard-negative mining on supplied classification losses; a 3:1 cap and positive-count normalization are shown, without default-box matching. Use the shared setup.

Shared setup for this chapter
softmax <- function(x) {
  if(is.null(dim(x))) {e<-exp(x-max(x)); return(e/sum(e))}
  t(apply(x,1,function(v) {e<-exp(v-max(v)); e/sum(e)}))
}
bilinear <- function(a,y,x) {
  y<-min(max(y,0),nrow(a)-1); x<-min(max(x,0),ncol(a)-1)
  y0<-floor(y); x0<-floor(x); y1<-min(y0+1,nrow(a)-1); x1<-min(x0+1,ncol(a)-1)
  dy<-y-y0; dx<-x-x0
  (1-dy)*((1-dx)*a[y0+1,x0+1]+dx*a[y0+1,x1+1])+dy*((1-dx)*a[y1+1,x0+1]+dx*a[y1+1,x1+1])
}
positive<-c(TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)
ce<-c(.2,.9,.1,.3,.8,.4,.05,.7,.6,.2)
pos_n<-sum(positive); negative<-which(!positive)
keep<-head(negative[order(ce[negative],decreasing=TRUE)],3*pos_n)
loc_sum<-.7; loss<-(sum(ce[positive])+sum(ce[keep])+loc_sum)/pos_n
stopifnot(length(keep)==6,!any(positive[keep]))
print(list(negative_indices_zero_based=keep-1,normalized_loss=loss))

Sources

From the CodeSplash reference, entry VIS004.