biapy.models.edsr

This module implements the Enhanced Deep Residual Networks for Single Image Super-Resolution (EDSR) model.

It includes the main EDSR model architecture and its essential building blocks:

  • SR_convblock: A residual convolutional block used within the EDSR network.

  • SR_upsampling: An upsampling block employing sub-pixel convolution (PixelShuffle) for efficient image scaling.

The code is adapted from the Keras EDSR example, providing a PyTorch implementation for both 2D and 3D image super-resolution tasks.

class biapy.models.edsr.EDSR(ndim=2, num_filters=64, num_of_residual_blocks=16, upsampling_factor=2, num_channels=3)[source]

Bases: Module

Enhanced Deep Residual Networks for Single Image Super-Resolution (EDSR) model.

Reference: Enhanced Deep Residual Networks for Single Image Super-Resolution.

Code adapted from https://keras.io/examples/vision/edsr

forward(x)[source]

Perform the forward pass of the EDSR model.

The input x first goes through an initial convolution. The output of this convolution is then passed through a series of residual blocks. A global residual connection adds the initial convolutional output (after another convolution) to the output of the residual blocks. Finally, the combined features are upsampled and mapped to the desired number of output channels.

Parameters:

x (torch.Tensor) – The input low-resolution image tensor. Expected shape for 2D: (batch_size, num_channels, height, width). Expected shape for 3D: (batch_size, num_channels, depth, height, width).

Returns:

The super-resolved output image tensor. The spatial dimensions are upscaled by upsampling_factor, and the number of channels matches num_channels.

Return type:

torch.Tensor

class biapy.models.edsr.SR_convblock(conv, num_filters)[source]

Bases: Module

A basic residual convolutional block for Super-Resolution networks.

This block consists of two convolutional layers with identity skip connection, designed to learn residual features effectively. It avoids batch normalization as per the original EDSR architecture.

forward(x)[source]

Perform the forward pass of the Super-Resolution convolutional block.

The input x passes sequentially through two convolutional layers. The output of the second convolution is then added back to the original input x via an identity skip connection.

Parameters:

x (torch.Tensor) – The input feature tensor. Expected shape: (batch_size, num_filters, …spatial_dims).

Returns:

The output feature tensor after processing through the residual block. Same shape as input x.

Return type:

torch.Tensor

class biapy.models.edsr.SR_upsampling(conv, num_filters, factor=2)[source]

Bases: Module

Super-resolution upsampling block using PixelShuffle.

This block handles the upscaling operation using sub-pixel convolutions, which is an efficient way to increase spatial resolution while reducing checkerboard artifacts often seen with transposed convolutions. It can perform 2x or 4x upsampling.

forward(x) Tensor[source]

Perform the forward pass of the Super-resolution upsampling block.

The input x first undergoes a convolution to prepare for the first PixelShuffle operation. If the upscaling factor is 4, an additional convolution and PixelShuffle are applied.

Parameters:

x (torch.Tensor) – The input feature tensor before upsampling. Expected shape: (batch_size, num_filters, …spatial_dims).

Returns:

The upsampled output tensor. Its spatial dimensions will be scaled by the specified factor.

Return type:

torch.Tensor