How kousumi04/denoiser works
1. System shape
This repo is an end-to-end image denoising system centered on DRUNet. It has three major layers: offline data/training code, a Python inference backend, and a Next.js frontend that sends user images to that backend.
2. Offline data preparation
preprocessing_pipeline/preprocess_sidd.py turns raw SIDD scene folders into paired noisy/clean patch tensors saved as .pt files. data_pipeline/drunet_datasets.py builds the other training input by pairing DIV2K clean images with multiple noisy domains and computing a per-sample sigma_hat.
3. Training boundary
training/training_drunet.py is the main training entry point, and training/fine_tune_drunet.py supports continued training from an existing checkpoint. The model architecture lives in training/models/drunet.py, so training is separated from the network definition.
4. Training outputs and shared model artifact
Training writes checkpoints into checkpoints/, including the unified model weights used for deployment. That checkpoint file is the main artifact connecting the offline ML pipeline to the serving system.
5. Evaluation and local inference
models_eval/denoiser_eval.py is the offline evaluation side, tracking quality with metrics such as PSNR. inference/infer_drunet.py is the local CLI path for denoising a single image with a chosen checkpoint, or estimating noise if a sigma is not provided.
6. Backend serving layer
app.py is the production inference service: a FastAPI app packaged for a Hugging Face Docker Space via Dockerfile and requirements-space.txt. On startup it loads checkpoints/DRUNET_DENOISER.pt, exposes GET /health, and exposes POST /denoise.
7. Request/response flow through the backend
The serving boundary is simple: the client uploads a noisy image as multipart form data using the field name image, and the backend returns a denoised PNG response. This means there is no persistent session state or database in the runtime path; inference is stateless and file/model-driven.
8. Frontend boundary
The UI is a Next.js app deployed on Vercel. The frontend uses a proxy/API route under app/api/denoise/route.ts to forward image uploads to the Hugging Face backend, with deployment behavior controlled by environment values like HF_IMAGE_API_URL, request method, request mode, and form field name.
9. Repository layout nuance
The repo contains a Next.js app structure both at the root and under frontend/. The root-level app/, next.config.mjs, and package files appear to be the active Vercel-facing app, while frontend/ mirrors the same frontend structure for an alternate packaging/deployment layout.
10. External services and runtime split
The live architecture is split across two hosted services: Vercel for the presentation layer and Hugging Face Spaces for GPU/CPU inference. The Python side uses PyTorch/FastAPI, while the frontend side uses TypeScript/Next.js; the only runtime dependency between them is the HTTP image-denoising endpoint.
Main entry points: app.py FastAPI app · denoise/route.ts API route · training_drunet.py Train DRUNet · denoise/route.ts Frontend API
Components 21
Offline ML
Data prep, training, evaluation, and local inference
- SIDD prep · Converts raw SIDD scenes into paired noisy/clean patch tensors
preprocessing_pipeline/preprocess_sidd.py - Train data · Builds DIV2K plus noisy-domain training pairs and sigma estimates
data_pipeline/drunet_datasets.py - Train DRUNet · Main training entry point for DRUNet
training/training_drunet.py - Fine-tune · Continues training from an existing checkpoint
training/fine_tune_drunet.py - DRUNet · Core denoising model architecture
training/models/drunet.py - Evaluate · Offline quality evaluation and PSNR-style metrics
models_eval/denoiser_eval.py - CLI infer · Single-image local denoising and noise estimation path
inference/infer_drunet.py - Checkpoint · Shared trained model weights used by serving and CLI inference
Backend Serving
FastAPI inference service and deployment packaging
- FastAPI app · Production inference service exposing health and denoise endpoints
app.py - Docker · Container image for the Hugging Face Space runtime
Dockerfile - Space deps · Python dependencies for the deployed backend
requirements-space.txt
Web Frontend
Next.js UI and API proxy layer
- API route · Root Next.js route that forwards image uploads to the backend
app/api/denoise/route.ts - Home page · Root-level Next.js page for the Vercel-facing app
app/page.tsx - App shell · Root-level Next.js layout and shared page chrome
app/layout.tsx - Frontend API · Mirrored Next.js API route for alternate frontend packaging
frontend/app/api/denoise/route.ts - Frontend page · Mirrored Next.js page entrypoint
frontend/app/page.tsx - Frontend shell · Mirrored Next.js layout and shared chrome
frontend/app/layout.tsx - Frontend pkg · Standalone frontend package and build configuration
frontend/package.json
External
Hosted runtime targets and third-party services
- Vercel · Deployment target for the presentation layer
- HF Space · Deployment target for the backend inference service
- User image · Noisy image uploaded from the browser
Connections 22
- SIDD prep → Train data: creates training pairs · Preprocessed SIDD data complements the broader training set construction
- Train data → Train DRUNet: feeds training · Training consumes paired noisy/clean examples and sigma metadata
- DRUNet → Train DRUNet: defines network · Training instantiates the DRUNet architecture
- DRUNet → Fine-tune: loads model · Fine-tuning continues from the same network definition
- Train DRUNet → Checkpoint: writes weights · Primary training output is the deployable checkpoint
- Fine-tune → Checkpoint: updates weights · Fine-tuning refreshes the shared model artifact
- Checkpoint → Evaluate: evaluated by · Offline evaluation scores trained checkpoints
- Checkpoint → CLI infer: used by · CLI inference loads the selected checkpoint
- Checkpoint → FastAPI app: loaded on startup · Backend service initializes the deployed model weights
- FastAPI app → HF Space: runs on · The FastAPI backend is packaged for the hosted inference runtime
- Docker → FastAPI app: packages · Container image bundles the backend service
- Space deps → FastAPI app: depends on · Runtime dependencies support the service stack
- User image → API route: uploads image · Browser sends multipart image data to the web proxy
- API route → FastAPI app: forwards request · Next.js API route relays the upload to the backend denoising endpoint
- API route → Vercel: served by · Root frontend is deployed as the presentation layer
- Home page → API route: calls · UI submits denoise requests through the local API route
- App shell → Home page: wraps · Shared page shell surrounds the home page
- Frontend pkg → Frontend API: contains · Alternate frontend package includes its own API proxy
- Frontend page → Frontend API: calls · Mirrored UI submits requests through its proxy route
- Frontend shell → Frontend page: wraps · Mirrored shell surrounds the frontend page
- Frontend API → HF Space: proxies to · Alternate deployment forwards uploads to the same backend service
- Frontend pkg → Vercel: deploys on · Frontend package is intended for Vercel-style deployment