Skip to content

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

Faster R-CNN

Faster R-CNN learns region proposals through a region proposal network sharing image features with the detector.

Runs in CodeSplash (Experimental) Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
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

Faster R-CNN learns region proposals through a region proposal network sharing image features with the detector. This makes proposal generation part of the learned detection system, rather than an external fixed algorithm.

Question / hypotheses

Can a learned proposal network supply high-recall regions efficiently enough for a two-stage detector? This is a modeling/evaluation question, not a formal null-hypothesis test.

Architecture / computational structure

A backbone produces features; an anchor-based RPN predicts objectness and box offsets, then proposal filtering supplies regions to a classification/refinement head. Modern FPN-based configurations differ from the original single-scale design.

Assumptions

Objects poorly matched by anchors or removed by proposal filtering cannot be recovered by the second stage. Crowding, class imbalance, domain shift and annotation inconsistency affect both proposal and classification learning.

Formula / computational definition

LRPN=Ncls−1∑iℓcls(pi,pi∗)+λNreg−1∑ipi∗ℓreg(ti,ti∗)L_{RPN}=N_{cls}^{-1}\sum_i\ell_{cls}(p_i,p_i^*)+\lambda N_{reg}^{-1}\sum_i p_i^*\ell_{reg}(t_i,t_i^*). Standard anchor targets include tx=(x−xa)/wat_x=(x-x_a)/w_a and tw=log⁡(w/wa)t_w=\log(w/w_a), with analogous y/height terms.

Parameters and notation

Notation: Here p_i is anchor objectness probability, p_i* its binary target, t_i and t_i* predicted/target box deltas, and N_cls/N_reg the specified normalizers. Lambda balances losses; x,y,w,h are box centers/sizes and subscript a denotes the anchor.

Learned or estimated: Backbone, RPN objectness/regression heads and region classifier/regressor parameters.

Hyperparameters and effects: Anchor sizes/ratios, proposal count, matching IoUs, region sampling, backbone strides, image scaling and NMS. Anchor coverage changes small/thin-object recall; filtering thresholds trade recall against speed.

Fitting, fine-tuning, and adaptation

Fit new detection heads and RPN with a frozen pretrained backbone initially, then unfreeze higher backbone stages using a smaller learning rate. Reconfigure anchors only after inspecting object sizes on training data. Adapt class-specific heads for new labels and validate source-class retention, proposal recall and target AP before broad unfreezing.

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. Report box AP by IoU and object size, RPN recall versus proposal budget, false positives per image and latency including postprocessing. Use scene/entity-disjoint evaluation where near-duplicate images exist.

Example application

Detect objects in images when a region-proposal stage provides a useful accuracy/compute tradeoff. 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: RPN center/size box encoding and decoding round trip; no anchor labeling, proposal suppression or network training. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python: versioned torchvision/Detectron-style implementations. R: full detector through an explicit Python bridge or custom native torch modules. The example encodes and decodes an anchor-relative target with a round-trip assertion.

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 — RPN center/size box encoding and decoding round trip; no anchor labeling, proposal suppression or network training. 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])
anchor=np.array([10.,20.,8.,6.]) # center x,y,width,height
target=np.array([12.,19.,12.,3.])
delta=np.r_[(target[:2]-anchor[:2])/anchor[2:],np.log(target[2:]/anchor[2:])]
decoded=np.r_[anchor[:2]+delta[:2]*anchor[2:],anchor[2:]*np.exp(delta[2:])]
assert np.allclose(decoded,target)
print('RPN deltas:',delta,'decoded:',decoded)
R

Component demo, not a trained model — RPN center/size box encoding and decoding round trip; no anchor labeling, proposal suppression or network training. 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])
}
anchor<-c(10,20,8,6) # center x,y,width,height
target<-c(12,19,12,3)
delta<-c((target[1:2]-anchor[1:2])/anchor[3:4],log(target[3:4]/anchor[3:4]))
decoded<-c(anchor[1:2]+delta[1:2]*anchor[3:4],anchor[3:4]*exp(delta[3:4]))
stopifnot(max(abs(decoded-target))<1e-12)
print(list(RPN_deltas=delta,decoded=decoded))

Sources

From the CodeSplash reference, entry VIS003.