SFNet trained on Rain13K

Demo: this checkpoint on 18 Rain13K test images, wiping from the rainy input to the model output, with each image's PSNR against the ground truth (Y channel). Rendered with the official code.

Unofficial mirror of the official SFNet weights from c-yn/SFNet. The weights are unchanged; this repository adds a weights-only model.safetensors copy, a config.json, an independent evaluation and rendered examples.

Model

SFNet (selective frequency network) is a three-scale convolutional U-Net built on MIMO-UNet, returning outputs at 1/4, 1/2 and full resolution (the last one is the result). Its multi-branch dynamic selective frequency module splits features into low- and high-frequency parts with learned, input-dependent low-pass filters (3x3 and 5x5) and reweights the parts with channel attention; a decoupling and modulation module enlarges the receptive field with global and window-based average pooling.

Results

On the five standard Rain13K test sets, Y-channel PSNR (dB) / SSIM:

Test set Images Measured for this mirror Reported in the official README
Rain100L 100 38.20 / 0.974
Rain100H 100 31.86 / 0.908
Test100 98 31.47 / 0.919
Test1200 1200 32.55 / 0.911
Test2800 2800 34.13 / 0.944
Test2800, outputs saved as JPEG (like test.py) 2800 33.67 / 0.936
Average of the five (Test2800 as JPEG) 4298 33.55 / 0.929 33.56 / 0.929

The first five rows are the true quality of the model: outputs saved losslessly as 8-bit PNG. The official test.py saves each output under its input's file name, and Test2800's inputs are .jpg, so its outputs are written as JPEG (Pillow's default quality 75) before scoring. That costs about 0.45 dB on Test2800, and the published Test2800 figure includes it. With the same JPEG step we reproduce the published numbers to within 0.01 dB.

We ran the official checkpoint with the official model code: the input is reflect-padded on the right and bottom to a multiple of 8 and the full-resolution output (the last of the three) is cropped back, the output is saved as 8-bit, and PSNR and SSIM are computed on the Y channel of MATLAB's rgb2ycbcr, with SSIM as in Wang et al. (11 x 11 Gaussian window, sigma 1.5), which is the MATLAB scoring the authors use. Evaluated on the test sets of our Rain13K mirror, byte-identical to the authors' test set download.

Examples

Files

File Content
deraining.pkl original checkpoint, exactly as released ({"model": state_dict, "optimizer": ..., "epoch": ...}, including the optimizer state at epoch 270)
model.safetensors the model weights, bit-exact, nothing else
config.json architecture, data, results and provenance (including the SHA-256 of the original file)
assets/ demo video, poster and the examples grid above

Usage

The model code lives in the official repository; clone it:

git clone https://github.com/c-yn/SFNet
import sys

import numpy as np
import torch
import torch.nn.functional as F
from huggingface_hub import hf_hub_download
from PIL import Image
from safetensors.torch import load_file

sys.path.insert(0, "SFNet/Image_deraining")
from models.SFNet import build_net

net = build_net()
net.load_state_dict(load_file(hf_hub_download("dronefreak/sfnet-rain13k", "model.safetensors")))
net.eval()

img = np.asarray(Image.open("input.png").convert("RGB"), dtype=np.float32) / 255.0
x = torch.from_numpy(img).permute(2, 0, 1)[None]
h, w = x.shape[2:]
x = F.pad(x, (0, -w % 8, 0, -h % 8), mode="reflect")  # sides must be multiples of 8
with torch.no_grad():
    y = net(x)[2][:, :, :h, :w].clamp(0, 1)  # outputs at 1/4, 1/2 and full size; keep the last
Image.fromarray((y[0].permute(1, 2, 0).numpy() * 255).round().astype(np.uint8)).save("output.png")

To use the original file instead:

sd = torch.load(hf_hub_download("dronefreak/sfnet-rain13k", "deraining.pkl"), map_location="cpu")["model"]
net.load_state_dict(sd)

Models trained on synthetic data may not transfer well to real photographs.

All mirrors of Yuning Cui's restoration models

PSNR / SSIM as measured by us with the authors' evaluation code on each checkpoint's test set (Y channel for deraining, shown on Rain100H).

Repository Model Trained on Task Params Test set PSNR / SSIM
convir-s-reside-its ConvIR-S RESIDE-ITS dehazing 5.53M SOTS indoor 41.53 / 0.996
convir-s-csd ConvIR-S CSD desnowing 5.53M CSD test 38.43 / 0.988
convir-s-dense-haze ConvIR-S Dense-Haze dehazing 5.53M Dense-Haze 17.45 / 0.648
convir-s-nh-haze ConvIR-S NH-Haze dehazing 5.53M NH-Haze 20.65 / 0.806
convir-s-i-haze ConvIR-S I-Haze dehazing 5.53M I-Haze 21.95 / 0.888
convir-s-o-haze ConvIR-S O-Haze dehazing 5.53M O-Haze 25.25 / 0.937
convir-b-reside-its ConvIR-B RESIDE-ITS dehazing 8.63M SOTS indoor 42.72 / 0.997
convir-b-csd ConvIR-B CSD desnowing 8.63M CSD test 39.10 / 0.990
convir-b-dense-haze ConvIR-B Dense-Haze dehazing 8.63M Dense-Haze 16.86 / 0.621
convir-b-nh-haze ConvIR-B NH-Haze dehazing 8.63M NH-Haze 20.66 / 0.802
convir-b-i-haze ConvIR-B I-Haze dehazing 8.63M I-Haze 22.45 / 0.887
convir-b-o-haze ConvIR-B O-Haze dehazing 8.63M O-Haze 25.35 / 0.934
convir-l-rain13k ConvIR-L Rain13K deraining 14.83M Rain100H 31.10 / 0.903
oknet-reside-its OKNet RESIDE-ITS dehazing 4.72M SOTS indoor 40.79 / 0.996
oknet-csd OKNet CSD desnowing 4.72M CSD test 37.99 / 0.988
oknet-dense-haze OKNet Dense-Haze dehazing 4.72M Dense-Haze 16.92 / 0.643
oknet-nh-haze OKNet NH-Haze dehazing 4.72M NH-Haze 20.48 / 0.804
oknet-i-haze OKNet I-Haze dehazing 4.72M I-Haze 21.72 / 0.870
oknet-o-haze OKNet O-Haze dehazing 4.72M O-Haze 25.64 / 0.939
sfnet-reside-its SFNet RESIDE-ITS dehazing 13.27M SOTS indoor 41.24 / 0.996
sfnet-rain13k (this repo) SFNet Rain13K deraining 13.27M Rain100H 31.86 / 0.908

Citation

If you use these weights, please cite the original work:

@inproceedings{cui2023selective,
  title     = {Selective Frequency Network for Image Restoration},
  author    = {Cui, Yuning and Tao, Yi and Bing, Zhenshan and Ren, Wenqi and Gao, Xinwei and Cao, Xiaochun and Huang, Kai and Knoll, Alois},
  booktitle = {The Eleventh International Conference on Learning Representations},
  year      = {2023}
}

Disclaimer

This is not an official release. All credit goes to the original authors (Yuning Cui, Yi Tao, Zhenshan Bing, Wenqi Ren, Xinwei Gao, Xiaochun Cao, Kai Huang, Alois Knoll). The weights are redistributed under the MIT license of the official repository (copyright Yuning Cui). If you are an author and want this mirror changed or removed, please open a discussion.

Downloads last month
-
Safetensors
Model size
13.3M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train dronefreak/sfnet-rain13k

Collection including dronefreak/sfnet-rain13k