Skip to content

Image understanding, generation, and 3D reconstruction · Semantic, instance and promptable segmentation · VIS010 · Architecture

Fully Convolutional Network for semantic segmentation (FCN)

The original semantic-segmentation FCN converts image-classification networks into dense predictors and combines coarse semantic features with finer spatial information.

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

The original semantic-segmentation FCN converts image-classification networks into dense predictors and combines coarse semantic features with finer spatial information. This named method is distinct from the general adjective fully convolutional applied to many later networks.

Question / hypotheses

Can coarse semantic features combined with fine spatial features classify every valid pixel? This is a modeling/evaluation question, not a formal null-hypothesis test.

Architecture / computational structure

Dense classifier layers become convolutions, coarse class-score maps are upsampled, and skip fusion from earlier resolutions refines predictions. FCN-32s/16s/8s are configurations of this one method family.

Assumptions

Pixel errors are spatially correlated, so pixel count is not the number of independent evaluation cases. Label maps require nearest-neighbor resizing or another label-preserving operation; bilinear interpolation of class IDs is invalid.

Formula / computational definition

pi,c=softmax⁡c(zi,c)p_{i,c}=\operatorname{softmax}_c(z_{i,c}), L=−∑i∈Vlog⁡pi,yiL=-\sum_{i\in V}\log p_{i,y_i}, where i indexes pixels and V excludes ignored labels. Skip fusion combines upsampled coarse scores with projected finer features.

Parameters and notation

Notation: Here z_i,c is a class logit for pixel i, p_i,c its normalized class probability, y_i the true class, and V the valid labeled-pixel set. The reduction may be a sum or a mean, but training and loss-weight interpretation must use one convention.

Learned or estimated: Convolutional backbone, score projections, learned upsampling when used, and skip-fusion parameters.

Hyperparameters and effects: Output stride, skip levels, input crop size, class weights, ignore-label convention and upsampling initialization. Coarse stride reduces compute but can erase thin structures and boundaries.

Fitting, fine-tuning, and adaptation

Initialize from an image classifier, fit score/upsampling layers, then fine-tune higher backbone blocks with a smaller learning rate. Adapt label heads for a new taxonomy and recheck ignore/background conventions. Validate source segmentation and target boundaries rather than only training pixel accuracy.

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 metrics, rare-class recall and image-level uncertainty. Use scene/entity-separated splits, and compare coarse-versus-skip outputs to understand boundary gains.

Example application

Assign a semantic class to every image pixel without identifying separate instances of the same class. 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: FCN-style coarse score upsampling, skip fusion and ignored-pixel binary loss; nearest-neighbor upsampling here is an illustrative replacement for learned/interpolated upsampling. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python/R: convolutional score heads and upsampling in PyTorch/native torch. The example fuses coarse/fine score maps and computes ignored-pixel-aware cross-entropy.

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 — FCN-style coarse score upsampling, skip fusion and ignored-pixel binary loss; nearest-neighbor upsampling here is an illustrative replacement for learned/interpolated upsampling. 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])
coarse=np.array([[1.,-1.],[-.5,1.5]])
upsampled=np.repeat(np.repeat(coarse,2,axis=0),2,axis=1)
fine=np.linspace(-.2,.2,16).reshape(4,4)
logits=upsampled+fine; prob=1/(1+np.exp(-logits))
target=np.array([[1,1,0,0],[1,-1,0,0],[0,0,1,1],[0,0,1,1]])
valid=target>=0; y=target[valid]; p=prob[valid]
loss=-np.mean(y*np.log(p)+(1-y)*np.log1p(-p))
assert valid.sum()==15 and logits.shape==(4,4)
print('ignored pixels:',(~valid).sum(),'pixel loss:',loss)
R

Component demo, not a trained model — FCN-style coarse score upsampling, skip fusion and ignored-pixel binary loss; nearest-neighbor upsampling here is an illustrative replacement for learned/interpolated upsampling. 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])
}
coarse<-matrix(c(1,-1,-.5,1.5),2,byrow=TRUE)
upsampled<-coarse[rep(1:2,each=2),rep(1:2,each=2)]
fine<-matrix(seq(-.2,.2,length.out=16),4,byrow=TRUE)
logits<-upsampled+fine; prob<-1/(1+exp(-logits))
target<-matrix(c(1,1,0,0,1,-1,0,0,0,0,1,1,0,0,1,1),4,byrow=TRUE)
valid<-target>=0; y<-target[valid]; p<-prob[valid]
loss<--mean(y*log(p)+(1-y)*log1p(-p))
stopifnot(sum(valid)==15,all(dim(logits)==c(4,4)))
print(list(ignored_pixels=sum(!valid),pixel_loss=loss))

Sources

From the CodeSplash reference, entry VIS010.