NAFNet SIDD denoising, smol (ONNX)

A compressed version of NAFNet (width 64, trained for real-noise denoising on SIDD), starting from the ONNX export by Qualcomm AI Hub (qualcomm/NAFNet-DeNoise). Produced with SmolAnything: structured pruning and low-rank replacements fitted on noisy calibration crops, with an LLM (Claude Opus 5.5, medium effort) deciding what to cut. No retraining. The replacements were fitted on noisy crops only; clean images were used only to choose the acceptance limit and to evaluate.

Original This model
Parameters 116M 97.5M (βˆ’15.9%)
MACs (256Γ—256 input) 63.2G 61.6G (βˆ’2.6%)
SIDD test PSNR ↑ 40.016 dB 39.961 dB (βˆ’0.055 dB)
SIDD test SSIM ↑ 0.9182 0.9178
PolyU PSNR ↑ (91 crops, see below) 36.789 dB 36.783 dB (βˆ’0.006 dB)
PolyU SSIM ↑ (91 crops) 0.9546 0.9546
Latency, RTX 3070 Ti (ONNX Runtime, CUDA) 32.6 ms 32.0 ms (βˆ’1.8%)
Latency, CPU, Ryzen 5 5600X (ONNX Runtime) 703 ms 700 ms (βˆ’0.4%)
ONNX file size 465.7 MB 390.2 MB (βˆ’16.2%)

The saved parameters sit in the low-resolution (16Γ—16) middle stack, so compute and latency barely change. The gain is mainly in model size.

Noisy SIDD test crop, original and optimized output, ground truth, difference

Noisy SIDD test crop, output of the original, output of this model, clean ground truth, absolute difference between the two outputs in 8-bit levels (mean 0.85). PSNR per crop in brackets. The crop was chosen by rule: of the 10% most detailed test crops, the one with the median PSNR change.

Input, output and validation

  • Fixed input shape: image is 1Γ—3Γ—256Γ—256, RGB, float32 in [0, 1] (8-bit value / 255), no mean/std normalization. This is the same as the Qualcomm export; the original PyTorch NAFNet accepts any size. Denoise larger images in 256Γ—256 tiles.
  • Output: denoised_image (1Γ—3Γ—256Γ—256), RGB in [0, 1]. Clip to [0, 1] before converting to 8 bit.
  • Validated on SIDD only (smartphone sRGB noise). Calibration used the 640 noisy validation crops of SIDD scenes 1-20; the test set is the 640 crops of the unseen scenes 21-40, scored against the clean ground truth (output clipped and rounded to 8 bit). The test set was evaluated only once, at the end. The NAFNet paper reports 40.30 dB on the full SIDD validation set; the 40.016 dB above is the original model on the scene 21-40 half.
  • Not overfitted to the calibration data: checked on PolyU (other scenes, five DSLR and mirrorless cameras), not a full PolyU benchmark. Each 512Γ—512 crop is denoised as 9 overlapping 256Γ—256 tiles; 9 of the 100 crops are left out because the original model already fails on them (dark, flat tiles produce unrelated colors and patterns; this model fails on the same ones). On the remaining 91 crops this model stays within 0.006 dB of the original, which improves on the noisy input by 1.0 dB. Check outputs on images with large dark, flat areas.

Usage

import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download

path = hf_hub_download("GavGuile/smolanything-nafnet-denoise", "onnx/model.onnx")
hf_hub_download("GavGuile/smolanything-nafnet-denoise", "onnx/model.onnx_data")
session = ort.InferenceSession(path, providers=["CUDAExecutionProvider", "CPUExecutionProvider"])

noisy = np.zeros((1, 3, 256, 256), dtype=np.float32)  # RGB crop, 8-bit value / 255
denoised = np.clip(session.run(["denoised_image"], {"image": noisy})[0], 0, 1)

What was changed

Found and verified by SmolAnything (full report with evidence and reasoning: study report):

  • Two residual branches removed: the first (conv/channel-attention) branch of middle blocks 4 and 6, 8.4M parameters.
  • Channel attention made low-rank: in the late middle blocks the channel attention convs (1M parameters each) barely depend on the image and were replaced at rank 4-16; in the early middle blocks at rank 32-64. Together another 10M parameters.
  • Left unchanged: everything that processes full-resolution pixels. Low-rank 1Γ—1 convs and removing encoder/decoder blocks cost too much accuracy, because NAFNet's SimpleGate multiplies two activations and amplifies approximation errors.
  • Each replacement's weights were fitted in closed form (ridge least squares) to reproduce the original layer outputs on calibration data. An edit was accepted only if the whole model's output stayed within 0.2% (per edit) and 0.45% (combined) relative L2 error; on the calibration scenes 0.45% corresponds to about 0.1 dB PSNR. The final model deviates from the original by 0.32% (held-out calibration crops).

License and credits

MIT, like the original model. All credit for the architecture and training goes to the NAFNet authors (Chen, Chu, Zhang and Sun, "Simple Baselines for Image Restoration", ECCV 2022); the ONNX export is by Qualcomm AI Hub. This repository only contains a post-training compressed version. Calibration and test data: SIDD (Abdelhamed, Lin and Brown, "A High-Quality Denoising Dataset for Smartphone Cameras", CVPR 2018).

SmolAnything is an independent project and is not affiliated with Hugging Face, Qualcomm or the authors of NAFNet.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for GavGuile/smolanything-nafnet-denoise

Quantized
(1)
this model