Image understanding, generation, and 3D reconstruction · Semantic, instance and promptable segmentation · VIS012 · Architecture
Pyramid Scene Parsing Network (PSPNet)
PSPNet augments local image features with pooled scene context at multiple spatial scales. This can help disambiguate locally similar textures whose semantic role depends on larger scene layout.
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
PSPNet augments local image features with pooled scene context at multiple spatial scales. This can help disambiguate locally similar textures whose semantic role depends on larger scene layout.
Question / hypotheses
Does pooled global and regional context resolve ambiguities that local appearance leaves uncertain? This is a modeling/evaluation question, not a formal null-hypothesis test.
Architecture / computational structure
A convolutional backbone feeds a pyramid pooling module. Several spatial bin grids pool features, project channels, upsample to the original feature size and concatenate with the local representation before dense prediction; auxiliary supervision helps training.
Assumptions
Context cues can become dataset shortcuts. Scene-disjoint splits are essential when backgrounds repeat; fixed crop distributions and image aspect ratios influence pooled representations. Pooling does not guarantee correct fine boundaries.
Formula / computational definition
, where pools/projects to a chosen bin grid and U upsamples. Main and auxiliary segmentation losses are weighted in the training objective.
Parameters and notation
Notation: Here H is a backbone feature map, P_k the k-th pooling/projection branch, U an upsampling operator and the double bar channel concatenation. Auxiliary-head loss is used during training with an explicit weight and can be discarded for inference.
Learned or estimated: Backbone, per-scale pooling projections, fusion convolutions, segmentation head and optional auxiliary head.
Hyperparameters and effects: Pooling bin grids, output stride, crop size, feature widths, auxiliary loss weight and interpolation conventions. Global pooling adds context but may dilute rare or tiny regions.
Fitting, fine-tuning, and adaptation
Fit target fusion/classification heads with a frozen backbone, then fine-tune higher layers at a smaller rate. Retain or remove the auxiliary head deliberately for training/inference. Validate target-scale coverage, context-shift behavior and source-class retention; adjust binning only through validation rather than test-image inspection.
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 mean/class IoU, boundary quality and robustness when background context changes. Ablate pooling branches and auxiliary loss, and measure inference cost including multi-scale evaluation if used.
Example application
Perform scene parsing where global layout helps distinguish visually similar local regions. 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: Pyramid pooling with 1×1 and 2×2 average-pooling bins, resized by repetition and concatenated with the input; learned projections are omitted. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.
Full-model route: Python: official PSPNet or verified segmentation frameworks. R: native torch pooling/fusion or bridge. The example reconstructs multi-bin pooled context on a tiny feature map.
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 — Pyramid pooling with 1×1 and 2×2 average-pooling bins, resized by repetition and concatenated with the input; learned projections 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])
x=np.arange(16,dtype=float).reshape(4,4)
global_branch=np.full_like(x,x.mean())
local=np.array([[x[2*i:2*i+2,2*j:2*j+2].mean() for j in range(2)] for i in range(2)])
local_branch=np.repeat(np.repeat(local,2,axis=0),2,axis=1)
fused=np.stack([x,global_branch,local_branch],axis=-1)
assert fused.shape==(4,4,3) and np.isclose(global_branch[0,0],7.5)
print('global context:',global_branch[0,0],'local bins:',local,'fused shape:',fused.shape)
Component demo, not a trained model — Pyramid pooling with 1×1 and 2×2 average-pooling bins, resized by repetition and concatenated with the input; learned projections 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])
}
x<-matrix(0:15,4,byrow=TRUE); global_branch<-matrix(mean(x),4,4)
local<-matrix(0,2,2)
for(i in 1:2) for(j in 1:2) local[i,j]<-mean(x[(2*i-1):(2*i),(2*j-1):(2*j)])
local_branch<-local[rep(1:2,each=2),rep(1:2,each=2)]
fused<-array(0,c(4,4,3)); fused[,,1]<-x; fused[,,2]<-global_branch; fused[,,3]<-local_branch
stopifnot(all(dim(fused)==c(4,4,3)),abs(global_branch[1,1]-7.5)<1e-12)
print(list(global_context=global_branch[1,1],local_bins=local,fused_shape=dim(fused)))
Sources
- Source 1arxiv.org
- Source 2github.com
From the CodeSplash reference, entry VIS012.