DenoiseSR4x
A custom PyTorch model for 4Γ image super-resolution and denoising, trained as part of the DLP-26T2-NPPE3 Kaggle competition.
The model takes a low-resolution/noisy RGB image and produces a 4Γ higher-resolution restored image.
Model Architecture
DenoiseSR4x is a custom residual super-resolution network with:
- 3-channel RGB input
- 64 feature channels
- 16 residual blocks
- GELU activations
- Residual scaling factor of 0.2
- Two 2Γ PixelShuffle upsampling blocks
- Overall 4Γ spatial upscaling
- Bicubic interpolation as the baseline
- Learned high-resolution residual added to the bicubic image
Conceptually:
Low-resolution RGB image
β
ββββββββββββββββ Bicubic 4Γ βββββββββββββββ
β β
βΌ β
Conv 3Γ3 β
β β
βΌ β
16 Residual Blocks β
β β
βΌ β
PixelShuffle 2Γ β
β β
βΌ β
PixelShuffle 2Γ β
β β
βΌ β
Conv 3Γ3 β
β β
βΌ β
Learned residual β
β β
βββββββββββββββββββ + ββββββββββββββββββββββ
β
βΌ
4Γ SR output
Training Configuration
The trained model used the following configuration:
| Parameter | Value |
|---|---|
| Scale | 4Γ |
| Feature width | 64 |
| Residual blocks | 16 |
| Residual scale | 0.2 |
| Training patch size | 64 Γ 64 LR |
| Batch size | 16 |
| Epochs | 36 |
| Optimizer | AdamW |
| Initial learning rate | 2e-4 |
| Weight decay | 1e-4 |
| LR scheduler | Cosine Annealing |
| Minimum learning rate | 1e-6 |
| Gradient clipping | 1.0 |
Files
best_sr_model.pt
The trained PyTorch checkpoint.
The checkpoint contains:
model
optimizer
scheduler
epoch
best_psnr
cfg
For inference, only the model state dictionary is required.
model.py
Contains the exact DenoiseSR4x architecture used to train the checkpoint, together with a convenient load_model() function.
requirements.txt
Lists the Python dependencies required to load and use the model.
Installation
pip install -r requirements.txt
Loading the Model
import torch
from model import load_model
device = "cuda" if torch.cuda.is_available() else "cpu"
model = load_model(
"best_sr_model.pt",
device=device,
)
model.eval()
Basic Inference
The model expects a normalized RGB tensor with shape:
[batch, 3, H, W]
with values in the range [0, 1].
Example:
import torch
from PIL import Image
from torchvision.transforms.functional import to_tensor, to_pil_image
from model import load_model
device = "cuda" if torch.cuda.is_available() else "cpu"
model = load_model(
"best_sr_model.pt",
device=device,
)
image = Image.open("input.png").convert("RGB")
x = to_tensor(image).unsqueeze(0).to(device)
with torch.inference_mode():
output = model(x).clamp(0, 1)
output_image = to_pil_image(
output.squeeze(0).cpu()
)
output_image.save("output.png")
Input and Output
For an input image of:
H Γ W
the model produces approximately:
4H Γ 4W
The model operates on RGB images normalized to [0, 1].
Tiled Inference
For large images, tiled inference can be used to reduce GPU memory usage.
The original competition inference configuration used:
Tile size: 96 Γ 96
Tile overlap: 16 pixels
Tile batch size: 8
The competition inference pipeline also used 8-way test-time augmentation (rotations and horizontal flips) and averaged the restored outputs.
Training
The model was trained using paired low-resolution/noisy images and clean high-resolution ground-truth images.
The training objective used:
- L1 loss during the initial training phase
- MSE loss during the final quarter of training
The best checkpoint was selected according to validation PSNR.
Checkpoint Information
The uploaded checkpoint is the best validation checkpoint saved during training.
The checkpoint was generated using:
torch.save(
{
"model": model.state_dict(),
"optimizer": optimizer.state_dict(),
"scheduler": scheduler.state_dict(),
"epoch": epoch,
"best_psnr": best_psnr,
"cfg": asdict(cfg),
},
"best_sr_model.pt",
)
Therefore, the checkpoint can be used to recover the trained model without retraining.
Framework
- PyTorch
- OpenCV
- NumPy