Super Resolution
Module: Computer Vision | Difficulty: Intermediate
Super-Resolution Objective
SRGAN Loss
ESRGAN Improvements
- RRDB (Residual in Residual Dense Block) β removes batch normalization
- Relativistic Discriminator β instead of
- Perceptual Loss β VGG features at multiple scales
PSNR and SSIM
import torch
import torch.nn as nn
class ResidualDenseBlock(nn.Module):
def __init__(self, nf=64, gc=32):
super().__init__()
self.conv1 = nn.Conv2d(nf, gc, 3, 1, 1)
self.conv2 = nn.Conv2d(nf + gc, gc, 3, 1, 1)
self.conv3 = nn.Conv2d(nf + 2 * gc, gc, 3, 1, 1)
self.conv4 = nn.Conv2d(nf + 3 * gc, gc, 3, 1, 1)
self.conv5 = nn.Conv2d(nf + 4 * gc, nf, 3, 1, 1)
self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
def forward(self, x):
x1 = self.lrelu(self.conv1(x))
x2 = self.lrelu(self.conv2(torch.cat([x, x1], 1)))
x3 = self.lrelu(self.conv3(torch.cat([x, x1, x2], 1)))
x4 = self.lrelu(self.conv4(torch.cat([x, x1, x2, x3], 1)))
return self.conv5(torch.cat([x, x1, x2, x3, x4], 1)) + x
Key Takeaways
- GAN-based SR produces sharper results than PSNR-optimized methods
- ESRGAN with RRDB achieves state-of-the-art perceptual quality
- Real-world SR must handle blur, noise, and compression artifacts