Mughees Ul Haq

Work 06 / 18

Teaching a small model to denoise like a big one

Photos taken in dim rooms come out grainy. I replaced the old denoiser with SCUNet, which fixed its artefacts, then distilled SCUNet into a convolution-only student a quarter of its size that runs on a CPU.

For
A property-media platform
Status
Distilled student exported to ONNX for CPU
Public photos with simulated noise, before and after the distilled denoiser.Noise addedDenoised

PSNR against the photo before I added noise: 24.5 dB with the noise, 30.07 dB after the student model.

Public photos with simulated noise, before and after the distilled denoiser.Noise addedDenoised

PSNR against the photo before I added noise: 25.03 dB with the noise, 28.55 dB after the student model.

Public photos with simulated noise, before and after the distilled denoiser.Noise addedDenoised

PSNR against the photo before I added noise: 25.41 dB with the noise, 29.52 dB after the student model.

I added simulated noise to public photos and ran the distilled student. Drag to compare. Against the clean original, PSNR rose from 24.5–25.4 dB to 28.6–30.1 dB on these three photos.

Photos: Interior, Duncan House, Polymath Park, Acme,… by w_lemay, CC BY-SA 2.0; NIND Saint-Remi ISOH1 by Trougnouf, CC BY 4.0; Kitchen, Paul Schweiker House and Studio, Me… by w_lemay, CC BY-SA 2.0. What I changed.

Teacher → student
17.9M → 5.2M
Parameters; ONNX 68.6 MB → 19.8 MB
Student against teacher
48–51 dB
PSNR; above 40 dB the difference is not visible
Clean photos needed
none
The teacher makes the targets
Training
about 4–5 h
40,000 iterations on one L4 GPU

The problem

The old denoiser, FFDNet, needed an estimate of how noisy each photo was and a gate that decided whether to run at all. It left soft lines and shifted black areas towards green. Switching to SCUNet fixed both and let me delete the noise estimate and the gate. The service still accepts the old noise field so that callers did not break, and ignores it.

Distillation

SCUNet uses Swin attention and is heavy for a CPU. So I froze it as a teacher and trained a convolution-only UNet student, with a global residual, to copy its output. That needs no clean ground truth: the teacher’s output on a noisy photo is the target.

The loss is a Charbonnier loss on pixels plus 0.1 times a Charbonnier loss on image gradients, which keeps edges sharp. Training used 256-pixel crops from about 20,000 noisy photos: 40,000 iterations at batch 16 on one L4 GPU, about four to five hours.

  1. Noisy photoAbout 20,000, no clean versions
  2. SCUNet teacherFrozen, 17.9M parameters
  3. TargetThe teacher’s output
  4. UNet studentConvolutions only, 5.2M parameters
The student learns to copy the teacher. Clean photos never enter training.

Running it

The student takes any input size. Large photos are cut into overlapping tiles padded to a multiple of 8 and blended back together with feathered edges, with dithering on the way out so smooth walls do not band. The output is always the same size as the input.

Limits

The student can only be as good as the teacher. Its 48–51 dB measures how closely it matches the teacher. It says nothing about how good the photo looks. I did not keep a CPU timing, so I don’t quote a speed-up.

Tools

SCUNet (teacher), PyTorch, ONNX Runtime, FFDNet (replaced).

The teacher model is SCUNet (Zhang et al., 2023).

The full write-up

There is a longer write-up of this project. It has client details in it, so email me if you’d like a redacted copy.