Skip to content

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

Fast R-CNN

Fast R-CNN shares convolutional computation across proposed regions and jointly trains classification and box refinement.

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

Fast R-CNN shares convolutional computation across proposed regions and jointly trains classification and box refinement. It addresses the repeated feature extraction and staged classifier training of R-CNN while still depending on external region proposals.

Question / hypotheses

Can shared image features and joint region-head training preserve localization quality while reducing repeated CNN work? This is a modeling/evaluation question, not a formal null-hypothesis test.

Architecture / computational structure

A backbone computes an image feature map once. RoI pooling quantizes each proposal into a fixed spatial grid, and shared region heads output class probabilities and category-dependent box offsets.

Assumptions

External proposal quality remains a bottleneck. Quantized pooling can misalign small objects; this is why later RoIAlign should not be silently substituted while claiming an exact Fast R-CNN reproduction.

Formula / computational definition

L(p,u,tu,v)=−log⁡pu+λ1u≥1∑jsmoothL1⁡(tju−vj)L(p,u,t^u,v)=-\log p_u+\lambda\mathbf1_{u\ge1}\sum_j\operatorname{smoothL1}(t_j^u-v_j), with true class u, target offsets v and predicted offsets tut^u. smoothL1⁡(x)=x2/2\operatorname{smoothL1}(x)=x^2/2 for ∣x∣<1|x|<1, otherwise ∣x∣−1/2|x|-1/2.

Parameters and notation

Notation: Here p is the class-probability vector, u the labeled class (0 denotes background), v the target box-offset vector, and t^u the predicted offsets for that class. Lambda balances localization against classification; j indexes four box coordinates.

Learned or estimated: Backbone, region-head, classifier and box-regressor weights. RoI pooling has geometric binning rules rather than learned interpolation weights.

Hyperparameters and effects: Proposal source/count, RoI pooled resolution, image scale, positive/negative sampling, localization-loss weight and NMS. Quantization convention affects pooled features and localization.

Fitting, fine-tuning, and adaptation

Initialize the shared backbone from image pretraining, fit detection heads, then jointly fine-tune selected backbone blocks with a smaller learning rate. Replace the class and box heads for incompatible labels. Revisit proposal matching and image scaling on target data, and check both source detection quality and target calibration after adaptation.

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. Evaluate box AP, small-object performance, proposal recall, per-image latency and sensitivity to region quantization. Compare sharing benefits against R-CNN with matched proposals.

Example application

Study a two-stage detector that shares image features while retaining externally generated candidate boxes. 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: A fixed 4×4 integer RoI pooled into 2×2 bins plus Smooth-L1 box loss; general RoI rounding and the classifier are omitted. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python: audited detection frameworks or original code. R: native torch simplified pooling/heads or bridge for full detector. The example implements quantized max pooling over a small RoI and Smooth L1 loss.

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 — A fixed 4×4 integer RoI pooled into 2×2 bins plus Smooth-L1 box loss; general RoI rounding and the classifier are omitted. 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])
roi=np.arange(1,17,dtype=float).reshape(4,4)
pooled=np.array([[roi[2*i:2*i+2,2*j:2*j+2].max() for j in range(2)] for i in range(2)])
pred=np.array([.2,-.1,1.5,0]); target=np.array([0,0,0,.2])
e=pred-target
smooth=np.where(np.abs(e)<1,.5*e**2,np.abs(e)-.5)
assert np.array_equal(pooled,[[6,8],[14,16]])
print('RoI pooled:',pooled,'Smooth-L1 sum:',smooth.sum())
R

Component demo, not a trained model — A fixed 4×4 integer RoI pooled into 2×2 bins plus Smooth-L1 box loss; general RoI rounding and the classifier are omitted. 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])
}
roi<-matrix(1:16,nrow=4,byrow=TRUE)
pooled<-matrix(0,2,2)
for(i in 1:2) for(j in 1:2) pooled[i,j]<-max(roi[(2*i-1):(2*i),(2*j-1):(2*j)])
pred<-c(.2,-.1,1.5,0); target<-c(0,0,0,.2); e<-pred-target
smooth<-ifelse(abs(e)<1,.5*e^2,abs(e)-.5)
stopifnot(all(pooled==matrix(c(6,8,14,16),2,byrow=TRUE)))
print(list(RoI_pooled=pooled,Smooth_L1_sum=sum(smooth)))

Sources

From the CodeSplash reference, entry VIS002.