Skip to content

Image understanding, generation, and 3D reconstruction · Image generation and restoration · VIS024 · Model

SRGAN / ESRGAN perceptual super-resolution family

SRGAN and its ESRGAN successor combine adversarial and perceptual learning for image super-resolution. They are grouped as one related family here: ESRGAN changes the generator, discriminator objective and perceptual…

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

SRGAN and its ESRGAN successor combine adversarial and perceptual learning for image super-resolution. They are grouped as one related family here: ESRGAN changes the generator, discriminator objective and perceptual feature treatment, rather than being counted as a separate generic GAN concept.

Question / hypotheses

Which pixel, perceptual and adversarial loss balance produces useful super-resolution without unacceptable invented detail? This is a modeling/evaluation question, not a formal null-hypothesis test.

Architecture / computational structure

A residual generator upsamples a low-resolution image, a discriminator evaluates high-resolution realism, and a fixed feature network supplies a perceptual comparison. ESRGAN uses residual-in-residual dense blocks without batch normalization and a relativistic discriminator formulation, with perceptual features before activation.

Assumptions

Training downsampling/noise assumptions must resemble deployment. A plausible texture is not recovered ground truth, and repeated patterns can be hallucinated. Learned super-resolution is especially risky for measurement or identification when fidelity is not separately established.

Formula / computational definition

LG=λpix∥G(x)−y∥1+λperc∥ϕ(G(x))−ϕ(y)∥22+λadvLadvL_G=\lambda_{pix}\|G(x)-y\|_1+\lambda_{perc}\|\phi(G(x))-\phi(y)\|_2^2+\lambda_{adv}L_{adv}. Here x,yx,y are low/high-resolution pairs and ϕ\phi a fixed perceptual feature extractor. Exact pixel norms and adversarial definitions depend on the SRGAN/ESRGAN variant.

Parameters and notation

Notation: Here G predicts high-resolution output from x, y is its paired reference, phi is a fixed feature map and each lambda weights an objective term. The example uses a relativistic-average ESRGAN-style discriminator component, while the text covers the broader family.

Learned or estimated: Generator and discriminator weights; the perceptual feature extractor is normally fixed during super-resolution training. Degradation parameters may be specified externally rather than learned in the original family.

Hyperparameters and effects: Upscaling factor, degradation model, residual-block capacity, pixel/perceptual/adversarial weights, discriminator schedule and feature layers. Higher adversarial weight can improve texture realism while reducing exact reconstruction fidelity; feature-layer choice changes perceptual emphasis.

Fitting, fine-tuning, and adaptation

Pretrain a generator with a pixel loss, then introduce adversarial/perceptual losses according to the selected variant. For domain transfer, fit compatible upsampling/output blocks first, then lower-rate backbone refinement with target degradation data. Keep the feature extractor fixed unless deliberately studying a changed objective; monitor source retention and the fidelity-perception tradeoff.

How to use and calibrate

Split by source scene/object before cropping or creating degradations, and keep paired transformations spatially consistent. Report PSNR/SSIM alongside perceptual metrics and controlled visual assessment at the declared scale and degradation. Evaluate real target-domain images separately from synthetic bicubic pairs; inspect invented edges/textures and downstream measurement errors.

Example application

Improve visual quality of low-resolution natural images under a documented degradation model. This is a proposed use case, not a claim of validated performance on supplied real data.

Interpretation / pitfalls

Watch out

Realistic outputs can contain invented details. Evaluate fidelity to the paired target and the measurements or decisions the restored image will support. A correct component calculation does not validate the full architecture, checkpoint or deployment pipeline.

Python and R code examples

Scope: Pixel, fixed-feature and relativistic-average adversarial generator losses on tiny supplied vectors; toy features are not VGG, and this is not an SRGAN/ESRGAN model. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python: official SRGAN/ESRGAN code or verified restoration frameworks. R: native torch residual generator/discriminator or bridge. The examples calculate pixel, fixed-feature and adversarial loss terms; the fixed toy features are not VGG or a perceptual-quality benchmark.

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 — Pixel, fixed-feature and relativistic-average adversarial generator losses on tiny supplied vectors; toy features are not VGG, and this is not an SRGAN/ESRGAN model. 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])
target=np.array([.1,.8,.4,.9]); pred=np.array([.2,.65,.35,.95])
phi=np.array([[1.,-1.,0.,0.],[0.,0.,1.,-1.]])
pixel=np.abs(pred-target).mean(); perceptual=np.mean((phi@pred-phi@target)**2)
c_real=np.array([1.,.8]); c_fake=np.array([-.2,.1])
sigmoid=lambda x: 1/(1+np.exp(-x))
real_relative=sigmoid(c_real-c_fake.mean()); fake_relative=sigmoid(c_fake-c_real.mean())
g_adv=-np.mean(np.log1p(-real_relative))-np.mean(np.log(fake_relative))
loss=.01*pixel+perceptual+.005*g_adv
assert np.isfinite(loss) and loss>0
print('pixel:',pixel,'toy-feature:',perceptual,'relativistic G:',g_adv,'weighted total:',loss)
R

Component demo, not a trained model — Pixel, fixed-feature and relativistic-average adversarial generator losses on tiny supplied vectors; toy features are not VGG, and this is not an SRGAN/ESRGAN model. 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])
}
target<-c(.1,.8,.4,.9); pred<-c(.2,.65,.35,.95)
phi<-matrix(c(1,-1,0,0,0,0,1,-1),2,byrow=TRUE)
pixel<-mean(abs(pred-target)); perceptual<-mean((phi%*%pred-phi%*%target)^2)
c_real<-c(1,.8); c_fake<-c(-.2,.1); sigmoid<-function(x) 1/(1+exp(-x))
real_relative<-sigmoid(c_real-mean(c_fake)); fake_relative<-sigmoid(c_fake-mean(c_real))
g_adv<--mean(log1p(-real_relative))-mean(log(fake_relative))
loss<-.01*pixel+perceptual+.005*g_adv
stopifnot(is.finite(loss),loss>0)
print(list(pixel=pixel,toy_feature=perceptual,relativistic_G=g_adv,weighted_total=loss))

Sources

From the CodeSplash reference, entry VIS024.