Photo Denoising Autoencoder
A plain convolutional denoising autoencoder that removes Gaussian noise from colour photos, built for an M.Tech Deep Learning term paper. The encoder squeezes the photo to a quarter of its width and height; the decoder rebuilds a clean photo from that bottleneck alone. There are no skip connections.
Try it: live demo
Intended use
Teaching and demonstrating denoising autoencoders: removing synthetic additive white Gaussian noise (σ 5–50 on the 0–255 scale) from natural photos. It is not meant for real camera noise, or for medical or forensic images.
How to use
pip install torch huggingface_hub safetensors scikit-image pillow numpy
from huggingface_hub import hf_hub_download
hf_hub_download("nisarganag/photo-denoising-autoencoder", "model.py", local_dir=".") # the model code lives in this repo
import numpy as np
from PIL import Image
from model import DenoisingAutoencoder, add_gaussian_noise, denoise, image_to_tensor, tensor_to_image
model = DenoisingAutoencoder.from_pretrained("nisarganag/photo-denoising-autoencoder").eval()
clean = image_to_tensor(np.array(Image.open("photo.png").convert("RGB")))
noisy = add_gaussian_noise(clean, sigma=25)
Image.fromarray(tensor_to_image(denoise(model, noisy))).save("cleaned.png")
The repo also has model.onnx, the same network exported for ONNX Runtime (input noisy, output clean,
shape 1×3×H×W with H and W multiples of 4, values in [0, 1]). The live demo runs it in your browser.
Training data
- Training: 400 photos from the Berkeley Segmentation Dataset (BSDS500), which UC Berkeley makes available for non-commercial research and educational purposes. Another 32 were held out for validation. The 68 CBSD68 test photos were excluded by matching pixel content.
- Testing: CBSD68 (the 68 colour BSDS photos used in the denoising literature) and Kodak24 (the Kodak Lossless True Color Image Suite, which r0k.us describes as released by the Eastman Kodak Company for unrestricted usage).
- Noise: synthetic Gaussian noise, with noisy images clipped to the valid [0, 1] range.
Training procedure
- epochs: 17
- patch size: 64
- batch size: 32
- patches per image: 64
- optimizer: Adam, learning rate 0.001 with cosine decay to 1e-05
- loss: mean squared error
- training sigma: uniform 5-50, one per patch
- train photos: 400
- validation photos: 32
- parameters: 1987203
- device: Apple M4 GPU (PyTorch MPS)
- best epoch: 17
- training minutes: 46.9
Results on CBSD68
Mean PSNR (dB) / SSIM over the 68 photos; higher is better. Rows marked "reported" are published numbers from Zhang et al. (FFDNet, IEEE TIP 2018), quoted for reference and not reproduced here. They were measured with un-clipped noise. Clipping the noisy photos, as done here, makes the task slightly easier (at σ = 50 the noisy input itself scores 15.00 dB here, against 14.15 dB for un-clipped noise), so the reported rows are not a like-for-like comparison.
| Method | σ=15: PSNR / SSIM | σ=25: PSNR / SSIM | σ=50: PSNR / SSIM |
|---|---|---|---|
| Noisy input | 24.84 / 0.592 | 20.53 / 0.417 | 15.00 / 0.219 |
| Gaussian blur | 27.81 / 0.715 | 26.06 / 0.666 | 23.21 / 0.557 |
| Median filter | 26.89 / 0.718 | 24.90 / 0.592 | 22.47 / 0.445 |
| Non-local means | 28.79 / 0.799 | 25.90 / 0.690 | 22.95 / 0.575 |
| Autoencoder (ours) | 32.97 / 0.922 | 30.65 / 0.876 | 27.41 / 0.776 |
| CBM3D (reported) | 33.52 / – | 30.71 / – | 27.38 / – |
| CDnCNN (reported) | 33.89 / – | 31.23 / – | 27.92 / – |
Limitations
- Output is somewhat soft. The finest detail, such as thin lines and fine textures, is smoothed, because all information has to pass through a quarter-resolution bottleneck.
- Trained only on synthetic Gaussian noise of σ 5–50. Beyond σ 50 it degrades gracefully: it stays well ahead of classical filters at σ 75, but the colours turn blotchy. It fails on salt-and-pepper noise. Real camera noise and JPEG artefacts were not tested.
- Trained on only 400 photos.
License
MIT for the code and weights. The training photos (BSDS500) are made available by UC Berkeley for non-commercial research and educational purposes only.