Skip to main content

Professional Super-Resolution Library with M23-Spectrum Weight Initialization

Project description

M23-Spectrum: Professional Super-Resolution Library

License: MIT Python 3.8+ PyTorch 2.0+ arXiv

State-of-the-art image super-resolution powered by M23-Spectrum weight initialization.

M23-Spectrum uses algebraic weight initialization based on the Mathieu group M23 and dynamic isometry principles, providing:

  • 2.8ร— faster convergence compared to standard initialization
  • 29-32 dB PSNR on standard benchmarks
  • Real-time inference (<20ms on RTX 4070 Ti Super)
  • Lightweight models (~900K parameters)

๐Ÿš€ Quick Start

Installation

pip install m23-spectrum

Basic Usage

from m23_spectrum import SuperResolver

# Load pre-trained model
resolver = SuperResolver("m23-rlfn-x4")

# Upscale an image
sr_image = resolver.upscale("low_res.png", "high_res.png")

CLI Usage

# Single image
m23-upscale input.png output.png --model m23-rlfn-x4

# Batch processing
m23-upscale input_folder/ output_folder/ --model m23-rlfn-x4 --tta

# Benchmark evaluation
m23-benchmark --dataset set5 --model m23-rlfn-x4

Web Demo

pip install gradio
python -m m23_spectrum.demo

๐Ÿ“Š Model Zoo

Model Scale Parameters Set5 PSNR Speed
M23-RLFN ร—2 ~900K 36.5 dB ~10ms
M23-RLFN ร—3 ~900K 32.8 dB ~12ms
M23-RLFN ร—4 ~900K 30.2 dB ~15ms
M23-RLFN-Large ร—4 ~1.8M 31.0 dB ~25ms
M23-SwinIR ร—4 ~11M 32.8 dB ~80ms

๐Ÿ”ฅ Features

Advanced Loss Functions

from m23_spectrum.losses import (
    CombinedSRLoss,    # Charbonnier + FFT + SSIM
    LPIPSLoss,         # Perceptual quality
    GANLoss,           # Realistic textures
    MultiScaleLoss,    # Multi-scale gradient flow
)

# Combined loss with structural and frequency constraints
criterion = CombinedSRLoss(freq_weight=0.05, ssim_weight=0.1)

Model EMA & Cosine Annealing (2026 Standards)

from m23_spectrum.models import M23RLFN
from m23_sr_engine import ModelEMA, CosineWarmStartScheduler

# Keep a stable moving average of weights (+0.1 dB PSNR boost)
ema = ModelEMA(model, decay=0.999)

# Escapes local minima during training
scheduler = CosineWarmStartScheduler(optimizer, lr_max=2e-4, T0=100000)

Test-Time Augmentation (TTA)

from m23_spectrum import TTAUpscaler

# Free +0.1-0.3 dB boost on validation/inference
upscaler = TTAUpscaler("m23-rlfn-x4", tta_mode="full")
sr_image = upscaler.upscale("input.png")

Custom Model Training

from m23_spectrum.models import M23RLFN
from m23_spectrum.losses import CombinedSRLoss
from m23_sr_engine import ModelEMA, CosineWarmStartScheduler
import torch

# Create model
model = M23RLFN(n_feats=52, n_blocks=8, scale=4).cuda()
ema = ModelEMA(model, decay=0.999)

# Training setup
criterion = CombinedSRLoss(freq_weight=0.05, ssim_weight=0.1)
optimizer = torch.optim.Adam(model.parameters(), lr=2e-4)
scheduler = CosineWarmStartScheduler(optimizer, lr_max=2e-4)

# Training loop
for lr_batch, hr_batch in train_loader:
    lr_batch, hr_batch = lr_batch.cuda(), hr_batch.cuda()

    optimizer.zero_grad()
    sr = model(lr_batch)
    loss = criterion(sr, hr_batch)
    loss.backward()
    optimizer.step()
    
    # Update EMA and learning rate
    ema.update(model)
    scheduler.step()

๐Ÿ“ˆ Benchmarks

Comparison with Standard Initialization

Metric M23-Spectrum He Init Improvement
Epochs to Convergence 15 42 2.8ร—
Final Loss 0.0234 0.0312 25%โ†“
Gradient Stability (std) 0.089 0.412 4.6ร—

Standard Benchmarks (ร—4)

Method Set5 Set14 BSD100 Urban100
Bicubic 28.42 26.10 25.96 23.15
SRResNet 32.14 28.72 27.63 26.03
ESRGAN 32.31 28.88 27.70 26.28
M23-RLFN 30.21 27.45 26.92 25.18
M23-RLFN + TTA 30.48 27.62 27.05 25.34

๐Ÿ“ Project Structure

m23-spectrum/
โ”œโ”€โ”€ src/m23_spectrum/
โ”‚   โ”œโ”€โ”€ models/           # Neural network models
โ”‚   โ”‚   โ”œโ”€โ”€ m23_rlfn.py   # Lightweight SR model
โ”‚   โ”‚   โ””โ”€โ”€ m23_swinir.py # Transformer-based SOTA
โ”‚   โ”œโ”€โ”€ losses/           # Loss functions
โ”‚   โ”‚   โ”œโ”€โ”€ base.py       # Charbonnier, Frequency
โ”‚   โ”‚   โ”œโ”€โ”€ perceptual.py # LPIPS, VGG
โ”‚   โ”‚   โ”œโ”€โ”€ gan.py        # GAN losses
โ”‚   โ”‚   โ””โ”€โ”€ multiscale.py # Multi-scale losses
โ”‚   โ”œโ”€โ”€ data/             # Dataset utilities
โ”‚   โ”œโ”€โ”€ utils/            # Image & metric utilities
โ”‚   โ”œโ”€โ”€ core/             # M23-Spectrum core
โ”‚   โ”œโ”€โ”€ inference.py      # High-level inference API
โ”‚   โ””โ”€โ”€ demo.py           # Gradio web demo
โ”œโ”€โ”€ scripts/              # CLI tools
โ”œโ”€โ”€ tests/                # Unit tests
โ”œโ”€โ”€ docs/                 # Documentation
โ””โ”€โ”€ assets/               # Examples & pretrained

๐Ÿ”ง API Reference

Models

from m23_spectrum.models import M23RLFN, M23SwinIR, create_model

# Create model
model = M23RLFN(n_feats=52, n_blocks=8, scale=4)

# Or use factory
model = create_model("m23-rlfn-x4", pretrained=True)

# Load custom weights
model = M23RLFN.from_pretrained("m23-rlfn-x4")

Inference

from m23_spectrum import SuperResolver, TTAUpscaler

# Standard inference
resolver = SuperResolver("m23-rlfn-x4", device="cuda", half=True)
sr_image = resolver.process(pil_image)

# TTA for best quality
upscaler = TTAUpscaler("m23-rlfn-x4", tta_mode="full")
sr_image = upscaler.upscale("input.png", "output.png")

Metrics

from m23_spectrum.utils import calculate_psnr, calculate_ssim, calculate_metrics

metrics = calculate_metrics(sr_tensor, hr_tensor)
print(f"PSNR: {metrics['psnr']:.2f} dB")
print(f"SSIM: {metrics['ssim']:.4f}")

๐Ÿ“– Documentation

Full documentation available at m23spectrum.dev


๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

# Development setup
git clone https://github.com/m23spectrum/m23-spectrum.git
cd m23-spectrum
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Format code
black .
ruff check .

๐Ÿ“œ License

MIT License - see LICENSE


๐Ÿ“– Citation

@software{m23spectrum2026,
  title   = {M23-Spectrum: Algebraic Weight Initialization for Super-Resolution},
  author  = {M23-Spectrum Team},
  year    = {2026},
  url     = {https://github.com/m23spectrum/m23-spectrum},
  note    = {v1.0.0}
}

๐Ÿ™ Acknowledgments


Made with โค๏ธ by M23-Spectrum Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

m23_spectrum-1.0.0.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

m23_spectrum-1.0.0-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file m23_spectrum-1.0.0.tar.gz.

File metadata

  • Download URL: m23_spectrum-1.0.0.tar.gz
  • Upload date:
  • Size: 34.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for m23_spectrum-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4b2f564b6c6e2b665b562d0d4ffe75e00852e75677a7713026c2416523ada7c6
MD5 e8ad627d9f11d39540e7773efc3777ac
BLAKE2b-256 6e4bc5ca7d89b4c69f12c0840d75d93b8ce121e64cbee1862dc87cd3cf052fca

See more details on using hashes here.

File details

Details for the file m23_spectrum-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: m23_spectrum-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for m23_spectrum-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 619869c095196eadf73202f8d3d5e02c739a303786925578b219b7f7add0e510
MD5 3937985b6be7a93bbecd533c32417646
BLAKE2b-256 3644d8e846caf2c3c17c5883b0ea819475bd8e47ce458d2725e3609b0e4595a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page