Image understanding, generation, and 3D reconstruction · Object detection · VIS001 · Model
R-CNN
R-CNN detects objects by classifying externally proposed image regions using convolutional features. It is historically important because it connected pretrained image representations to localization;
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
R-CNN detects objects by classifying externally proposed image regions using convolutional features. It is historically important because it connected pretrained image representations to localization; it is computationally distinct from the shared-feature Fast and Faster R-CNN successors.
Question / hypotheses
Can pretrained region features distinguish object categories and refine candidate boxes in complete images? This is a modeling/evaluation question, not a formal null-hypothesis test.
Architecture / computational structure
Generate candidate regions, warp each region to the CNN input shape, extract features independently, classify with category-specific linear SVMs and refine boxes with regressors. The original pipeline has separate stages rather than one jointly optimized detector.
Assumptions
Proposal recall upper-bounds attainable detection recall. Cropping/warping can distort aspect ratios, and duplicated regions require suppression. Recognition accuracy on cropped objects does not establish localization accuracy in full scenes.
Formula / computational definition
For proposal feature , a linear class score is . SVM training minimizes regularized hinge loss ; class-specific regressors predict coordinate offsets.
Parameters and notation
Notation: Here r is a proposed image region, f(r) its CNN feature vector, c a class, i a training region, and y_ic is a binary class label in {−1,+1}; w_c and b_c define the fitted linear score. C is an SVM regularization tradeoff, unrelated to CNN channel count.
Learned or estimated: Fine-tuned CNN weights, category SVM coefficients and box-regression weights. External selective-search proposals are not a learned region-proposal network.
Hyperparameters and effects: Proposal count, warping size, positive/negative IoU rules, hard-negative mining, SVM penalty, box regression and NMS thresholds. More proposals increase recall and substantial per-region CNN cost.
Fitting, fine-tuning, and adaptation
Transfer a pretrained classifier backbone, fine-tune it on detection regions, fit the SVMs and regressors with the original staged protocol if reproducing R-CNN. For a new label set, refit class-specific components and cautiously adapt the backbone at lower learning rates. Validate proposal recall and source-class retention; updating only SVMs cannot repair missed proposals.
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 average precision across IoU thresholds, proposal recall, classwise errors and end-to-end latency including proposal generation. Separate classification failures from localization and missing-proposal failures.
Example application
Build a historical region-based detector baseline to study the value and cost of CNN region features. 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: Proposal IoU and the linear SVM hinge-loss component of original R-CNN; no CNN, proposal generator or SVM fitting. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.
Full-model route: Python: original research implementation or an explicitly reconstructed staged pipeline. R: native feature/SVM components plus a Python CNN bridge if needed. The example computes proposal-label IoUs and a linear hinge objective, not full R-CNN inference.
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.
Component demo, not a trained model — Proposal IoU and the linear SVM hinge-loss component of original R-CNN; no CNN, proposal generator or SVM fitting. 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])
boxes=np.array([[0,0,2,2],[1,1,3,3],[4,4,5,5]],float)
gt=np.array([0,0,2,2],float)
inter=np.maximum(np.minimum(boxes[:,2:],gt[2:])-np.maximum(boxes[:,:2],gt[:2]),0).prod(axis=1)
area=np.prod(boxes[:,2:]-boxes[:,:2],axis=1)
iou=inter/(area+4-inter)
labels=np.where(iou>=.5,1.,-1.) # illustrative binary assignment
scores=np.array([1.4,.2,-.8])
hinge=np.maximum(0,1-labels*scores)
assert np.allclose(iou,[1,1/7,0])
print('IoU:',iou,'hinge:',hinge,'mean:',hinge.mean())
Component demo, not a trained model — Proposal IoU and the linear SVM hinge-loss component of original R-CNN; no CNN, proposal generator or SVM fitting. 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])
}
boxes<-matrix(c(0,0,2,2, 1,1,3,3, 4,4,5,5),ncol=4,byrow=TRUE)
gt<-c(0,0,2,2)
inter<-apply(boxes,1,function(b) prod(pmax(pmin(b[3:4],gt[3:4])-pmax(b[1:2],gt[1:2]),0)))
area<-apply(boxes[,3:4]-boxes[,1:2],1,prod)
iou<-inter/(area+4-inter)
labels<-ifelse(iou>=.5,1,-1) # illustrative binary assignment
scores<-c(1.4,.2,-.8); hinge<-pmax(1-labels*scores,0)
stopifnot(max(abs(iou-c(1,1/7,0)))<1e-12)
print(list(IoU=iou,hinge=hinge,mean=mean(hinge)))
Sources
- Source 1arxiv.org
- Source 2github.com
From the CodeSplash reference, entry VIS001.