How tyvirgo/higan works
1. This repository is a PyTorch-based image super-resolution project centered on the HIGAN family of models. It provides both training and evaluation code, plus pretrained checkpoints for three model sizes: HIGAN-S, HIGAN, and HIGAN-L.
2. The architecture is organized around a single entry point, src/main.py, which likely dispatches between training and test-only execution based on command-line options. Configuration is handled through src/option.py, with src/template.py and src/utility.py supporting experiment setup, logging, and run-time orchestration.
3. The core model boundary lives in src/model/. This folder contains the HIGAN implementations (higan_6block.py, higan_10block.py) as well as baseline/reference architectures such as EDSR, VDSR, RFDN, and shared building blocks in block.py, common.py, arch_util.py, and atten.py. The repo is therefore not just a single network, but a model zoo with HIGAN as the main target.
4. Data ingestion is isolated in src/data/. The repository supports multiple super-resolution datasets and dataset variants, including DIV2K, DF2K, Flickr2K, SR291, benchmark/test datasets, JPEG variants, demo inputs, and video data. srdata.py appears to be the common dataset base class, while the other files adapt it to specific sources and evaluation formats.
5. The data flow for training is typical SR supervision: low-resolution inputs and corresponding high-resolution targets are loaded from dataset-specific readers, then cropped into patches and batched through src/dataloader.py. The repo’s training commands in the README indicate patch-based training, scale-factor-specific runs, and dataset-path configuration through options.
6. The training loop is concentrated in src/trainer.py. This is the main subsystem that likely connects the model, optimizer, learning-rate schedule, loss functions, and periodic evaluation. The repo also includes src/loss/ with adversarial, discriminator, and VGG-based perceptual losses, indicating support for both plain reconstruction training and GAN/perceptual training variants.
7. Evaluation and reporting are separated from training. The README’s demo.sh workflow and the --test_only flag suggest that test runs load pretrained checkpoints from ./pretrained/ and write results into experiment-specific output folders. This boundary keeps inference side effects, metrics, and image saving out of the training loop.
8. There is explicit support for benchmark-style testing over standard SR datasets such as Set5, Set14, B100, Urban100, and Manga109. The src/data/benchmark.py and src/data/div2k_test.py files suggest a distinction between training datasets and standardized test datasets, which is important for architecture diagrams showing separate ingestion paths.
9. Video super-resolution is a separate functional path, not just an afterthought. The presence of src/videotester.py and src/data/video.py indicates a dedicated inference/testing path for sequential frame inputs, likely sharing the same model backbone but different sampling and I/O logic.
10. The repository depends on CUDA-enabled PyTorch tooling and expects Python 3.8. The README also notes that this code is built on EDSR-PyTorch, which helps explain the overall layout: option parsing, dataset factories, trainer abstraction, and model modules are all in the style of a reusable SR research framework.
11. Pretrained weights are versioned by model family and upscaling factor under pretrained/, with separate folders for x2, x3, and x4 checkpoints. This means the deployment boundary is checkpoint-based rather than service-based: the model graph is defined in code, then instantiated with a matching .pt file for inference or fine-tuning.
12. For an architecture diagram, the key flow is: command-line options enter main.py, configuration selects dataset and model, data loaders feed LR/HR pairs into the HIGAN backbone, losses and optimizer are managed by the trainer during training, and checkpoints/results are emitted to experiment folders during evaluation or demo runs.
Main entry points: main.py main · videotester.py tester · srdata.py srdata · trainer.py trainer
Components 19
Entry & orchestration
CLI entrypoint, option parsing, and run setup.
- main · Single command entry for train or test execution.
src/main.py - options · Parses command-line flags and experiment settings.
src/option.py - template · Builds experiment templates and runtime structure.
src/template.py - utility · Shared helpers for logging, filesystem, and orchestration.
src/utility.py
Data pipeline
Training and evaluation dataset loading.
- dataloader · Creates loaders and batches for SR datasets.
src/dataloader.py - srdata · Common dataset base class used by SR datasets.
src/data/srdata.py - train sets · DIV2K, DF2K, Flickr2K, SR291, and JPEG variants.
src/data/div2k.py - test sets · Benchmark and DIV2K test readers for standard SR evaluation.
src/data/benchmark.py - demo/video · Demo inputs and video frame loading for sequential inference.
src/data/demo.py
Model zoo
HIGAN and baseline SR architectures.
- HIGAN · Main HIGAN family implementations for 6-block and 10-block variants.
src/model/higan_6block.py - baselines · Reference SR architectures such as EDSR, VDSR, and RFDN.
src/model/edsr.py - building blocks · Common layers, attention, and architecture utilities reused by models.
src/model/block.py
Training & loss
Optimization loop and training objectives.
Inference & demo
Test-only and video/demo execution paths.
- tester · Test-only execution path for loading checkpoints and reporting results.
src/videotester.py - video tester · Specialized sequential-frame evaluation for video SR.
src/videotester.py
Weights
Pretrained checkpoints grouped by model family.
- HIGAN-S · Pretrained weights for the small HIGAN model across x2, x3, x4.
pretrained/HIGAN-S_Div2k/higans_x2.pt - HIGAN · Pretrained weights for the base HIGAN model across x2, x3, x4.
pretrained/HIGAN_Div2K/higan_x2.pt - HIGAN-L · Pretrained weights for the large HIGAN model across x2, x3, x4.
pretrained/HIGAN-L_Div2k/higanl_x2.pt
Connections 23
- main → options: reads args · CLI options determine mode, dataset, scale, and paths.
- main → template: builds run · Experiment naming and folder layout are prepared early.
- main → utility: uses helpers · Main flow relies on common runtime utilities.
- main → dataloader: creates loaders · Dispatches into training or evaluation data pipelines.
- dataloader → srdata: extends · Dataset wrappers share the common SR dataset base.
- srdata → train sets: loads · Training data readers provide LR/HR supervision pairs.
- srdata → test sets: loads · Benchmark readers provide standardized evaluation samples.
- srdata → demo/video: loads · Demo and video inputs follow specialized read paths.
- main → HIGAN: selects model · Configured model family is instantiated from the model zoo.
- main → baselines: selects model · Alternative SR backbones are available through the same boundary.
- HIGAN → building blocks: reuses · HIGAN variants are composed from shared architectural blocks.
- baselines → building blocks: reuses · Baseline architectures also depend on shared modules.
- main → trainer: trains · Training mode hands off control to the trainer loop.
- trainer → losses: optimizes with · Trainer combines reconstruction, adversarial, and perceptual losses.
- trainer → HIGAN: updates · Backpropagation targets the selected super-resolution model.
- trainer → dataloader: consumes batches · Mini-batches from the loader feed the optimization loop.
- main → tester: test only · Evaluation mode bypasses training and runs inference/reporting.
- tester → HIGAN: loads · Test runs use matching pretrained checkpoints when available.
- tester → HIGAN-S: loads · Small-model checkpoints support inference and demo workflows.
- tester → HIGAN-L: loads · Large-model checkpoints support inference and demo workflows.
- tester → test sets: evaluates on · Standard benchmark datasets are used for reported results.
- video tester → demo/video: streams · Video SR uses frame-sequence input rather than image batches.
- video tester → HIGAN: loads · Video inference reuses pretrained backbone checkpoints.