Spaces:
Running
Running
| title: SpectraGAN | |
| emoji: πΌοΈ | |
| colorFrom: blue | |
| colorTo: green | |
| sdk: gradio | |
| sdk_version: 5.31.0 | |
| app_file: app.py | |
| pinned: false | |
| license: apache-2.0 | |
| # πΌοΈ SpectraGAN β Multi-Model Upscaler Comparison | |
| A Gradio web app that lets you upscale an image with **multiple SR models simultaneously** and compare results side by side. | |
| Supported models: | |
| | Model | Architecture | Scale | | |
| |-------|-------------|-------| | |
| | Real-ESRGAN Γ2 | GAN (residual-in-residual dense block) | Γ2 | | |
| | Real-ESRGAN Γ4 | GAN (residual-in-residual dense block) | Γ4 | | |
| | SRCNN Γ4 | Shallow 3-layer CNN | Γ4 | | |
| | HResNet Γ4 | Deep residual network (EDSR-style) | Γ4 | | |
| | SR3 *(stub)* | Diffusion model | Γ4 β see note below | | |
| --- | |
| ## π Table of Contents | |
| 1. [Features](#features) | |
| 2. [Project Structure](#project-structure) | |
| 3. [Prerequisites](#prerequisites) | |
| 4. [Installation](#installation) | |
| 5. [Adding Your ONNX Models](#adding-your-onnx-models) | |
| 6. [Running Locally](#running-locally) | |
| 7. [SR3 Integration Guide](#sr3-integration-guide) | |
| 8. [Contributing](#contributing) | |
| 9. [License](#license) | |
| --- | |
| ## β¨ Features | |
| - **Side-by-side comparison** β run up to 4 models at once, results displayed in a 4-panel grid. | |
| - **Selective execution** β toggle any model on/off before running; unchecked models are skipped. | |
| - **Γ8 post-resize** β optionally apply a bicubic Γ2 pass on top of any Γ4 result. | |
| - **Tile-based inference** β large images are split into tiles matching each model's fixed input size, then stitched back together seamlessly. | |
| - **Per-result download** β each panel has its own PNG download button. | |
| - **Graceful degradation** β if a model file is missing (e.g. Drive ID not yet set), that panel is skipped without crashing the others. | |
| --- | |
| ## π Project Structure | |
| ``` | |
| spectragan/ | |
| βββ model/ | |
| β βββ Real-ESRGAN_x2plus.onnx # auto-downloaded | |
| β βββ Real-ESRGAN-x4plus.onnx # auto-downloaded | |
| β βββ SRCNN_x4.onnx # you provide β see below | |
| β βββ HResNet_x4.onnx # you provide β see below | |
| βββ app.py | |
| βββ requirements.txt | |
| βββ README.md | |
| ``` | |
| --- | |
| ## βοΈ Prerequisites | |
| - Python 3.10+ | |
| - `git` | |
| - A terminal / command prompt | |
| --- | |
| ## π§ Installation | |
| ```bash | |
| git clone https://github.com/ParamAhuja/SpectraGAN.git | |
| cd SpectraGAN | |
| python -m venv .venv | |
| source .venv/bin/activate # Linux/macOS | |
| # .venv\Scripts\activate # Windows | |
| pip install -r requirements.txt | |
| ``` | |
| --- | |
| ## ποΈ Adding Your ONNX Models | |
| The Real-ESRGAN weights are downloaded automatically from Google Drive on first run. | |
| For **SRCNN** and **HResNet** you need to: | |
| 1. Export your trained PyTorch model to ONNX: | |
| ```python | |
| import torch | |
| # SRCNN example | |
| from srcnn import SRCNN | |
| model = SRCNN() | |
| model.load_state_dict(torch.load("srcnn.pth")) | |
| model.eval() | |
| dummy = torch.randn(1, 3, 128, 128) | |
| torch.onnx.export( | |
| model, dummy, "SRCNN_x4.onnx", | |
| input_names=["input"], output_names=["output"], | |
| dynamic_axes={"input": {2: "H", 3: "W"}, "output": {2: "H", 3: "W"}} | |
| ) | |
| ``` | |
| 2. Upload the `.onnx` file to Google Drive and set **"Anyone with the link can view"**. | |
| 3. Copy the file ID from the share URL and update `DRIVE_IDS` in `app.py`: | |
| ```python | |
| DRIVE_IDS = { | |
| ... | |
| "srcnn_x4": "YOUR_SRCNN_DRIVE_FILE_ID_HERE", | |
| "hresnet_x4": "YOUR_HRESNET_DRIVE_FILE_ID_HERE", | |
| } | |
| ``` | |
| --- | |
| ## π Running Locally | |
| ```bash | |
| python app.py | |
| ``` | |
| Open `http://127.0.0.1:7860` in your browser. | |
| --- | |
| ## π SR3 Integration Guide | |
| SR3 (Super-Resolution via Repeated Refinement) is a **diffusion model** β it cannot be exported to a static ONNX graph because its inference involves a variable-length denoising loop. | |
| To add SR3: | |
| 1. Clone the reference implementation: | |
| ```bash | |
| git clone https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-Refinement | |
| ``` | |
| 2. Place your trained checkpoint at `model/sr3_x4.pth`. | |
| 3. Add `torch` and `torchvision` to `requirements.txt`. | |
| 4. Write a wrapper in `app.py`: | |
| ```python | |
| def run_sr3(input_img: Image.Image) -> Image.Image: | |
| # load config + model, run the denoising loop, return result | |
| ... | |
| ``` | |
| 5. Add `"sr3_x4"` to the `PANEL_KEYS` list and wire `run_sr3` into `compare_models`. | |
| --- | |
| ## π€ Contributing | |
| Pull requests welcome. Please open an issue first to discuss significant changes. | |
| --- | |
| ## π License | |
| Apache 2.0 β see `LICENSE`. | |
| --- | |
| ## π€ Author & Credits | |
| - Real-ESRGAN by [xinntao](https://github.com/xinntao/Real-ESRGAN) | |
| - SRCNN by Dong et al. (2014) | |
| - HResNet / EDSR by Lim et al. (2017) | |
| - SR3 by Ho et al. (2022) β [paper](https://arxiv.org/abs/2104.07636) | |