How kail8/unsupdis-pytorch works
1. Project purpose and overall shape
This repository is a PyTorch reimplementation of the UnsupDIS deep image stitching pipeline. Architecturally it is a two-stage ML system: an alignment stage that predicts coarse geometric alignment between paired images, followed by a fusion/reconstruction stage that produces the final stitched output.
2. Top-level workflow boundary
The repository is organized around command-line entry points rather than a service runtime. The main executables are train.py, test.py, inference_align.py, and inference_fuse.py, with main.sh documenting the intended end-to-end pipeline. The data flow is: raw paired images -> alignment model -> warped/aligned pairs -> fusion model -> stitched result.
3. Data layer and dataset contracts
data/*.yaml defines dataset locations and splits for UDIS-D and WarpedCOCO. The expected directory structure is fixed around paired inputs such as input1 and input2, with separate train/test splits. Text files like train.txt and test.txt act as split manifests. This is the primary boundary between the code and external data.
4. Two-stage model architecture
The mode flag in training/inference distinguishes the two subsystems: align and fuse. Alignment learns to register the two views; fusion consumes the aligned pair and reconstructs the final image. These are separate model families with separate YAML configs, checkpoints, loss behavior, and input resolution expectations.
5. Model configuration and backbone selection
models/*.yaml defines network layouts for alignment and fusion variants, including origin, variant, and YOLO-backed versions. The repo borrows the YOLOv5-style configuration system, so architecture is assembled from YAML and reused backbone components. The README notes that depth_multiple and width_multiple are used to select the backbone scale.
6. Model implementation boundary
Core neural network code lives in models/ and is split into reusable modules and model definitions. models/common.py, models/yolo.py, and models/experimental.py provide the YOLO-style building blocks and parsing logic; models/torchsummary.py is for inspection. The repo’s alignment and fusion networks are configured on top of this shared model framework.
7. Training pipeline
train.py is the orchestration layer for optimization. It reads a dataset config, a hyperparameter file, a model YAML, and optional pretrained weights. The repository uses different hyperparameter files for scratch training and fine-tuning, reflecting the stage-specific optimization strategy. Training artifacts are written under runs/train/ and later moved into weights/.
8. Inference and evaluation split
test.py handles batched evaluation metrics, while inference_align.py and inference_fuse.py generate visual outputs and intermediate artifacts. Alignment inference can produce metrics like RMSE and also save warped pairs for the next stage. Fusion inference takes the aligned data and emits the final stitched images.
9. Losses and geometry-aware utilities
utils/loss.py contains the training objectives, while utils/stitching.py and utils/general.py support image composition, geometric handling, and evaluation helpers. These utilities are part of the algorithmic core rather than generic plumbing because stitching quality depends on both alignment geometry and reconstruction losses.
10. Data loading and preprocessing
utils/datasets.py is the bridge from the dataset manifests to minibatches. It likely handles paired-image loading, resizing/cropping, and augmentation consistent with the stitch-pair task. This is where raw file structure is converted into tensors consumed by the training and inference code.
11. Runtime and dependency profile
The project is implemented in Python with PyTorch, and it relies on the YOLOv5 ecosystem for model structure and pretrained backbones. The README’s emphasis on pretrained yolov5*.pt weights shows that external checkpoints are part of the model initialization path, especially for the YOLO-based variants.
12. Artifacts and checkpoint layout
Checkpoints are organized under weights/align/... and weights/fuse/..., with training outputs copied from runs/train/exp. The pipeline explicitly uses one stage’s checkpoint as the initialization for the next stage, so checkpoint flow is a first-class architectural dependency.
13. Key external dependencies
The main external inputs are the datasets UDIS-D and WarpedCOCO, plus pretrained YOLOv5 backbones. The project also depends on the standard PyTorch training stack and image I/O libraries listed in requirements.txt. No server, database, or online API boundary appears in the architecture.
14. Important architectural tradeoff
The repo deliberately simplifies the original TensorFlow implementation by replacing heavier alignment components such as cost volume with lighter concatenation-based design choices. That tradeoff affects the diagram: the architecture is optimized for practical training speed and inference speed, not for maximum model fidelity to the original paper.
15. How to draw the system
A correct architecture diagram should show: external datasets and pretrained weights feeding a dataset/config layer; that layer feeding the alignment training/inference pipeline; alignment outputs generating warped pairs; warped pairs feeding the reconstruction training/inference pipeline; and utility modules supporting both stages for losses, stitching, and evaluation.
Main entry points: train.py Train · inference_align.py Align infer · inference_fuse.py Fuse infer · general.py General utils
Components 20
External inputs
Datasets and pretrained checkpoints consumed by the pipeline.
- UDIS-D · Paired-image stitching dataset used for training and evaluation.
data/UDIS-D - WarpedCOCO · Secondary paired-image dataset for training and testing.
data/WarpedCOCO - YOLO weights · Pretrained backbones used to initialize YOLO-backed variants.
Entry points
Command-line workflows for training, testing, and inference.
- Train · Stage-aware optimization entry point for alignment and fusion.
train.py - Test · Batched evaluation and metric reporting entry point.
test.py - Align infer · Produces warped/aligned pairs and alignment metrics.
inference_align.py - Fuse infer · Consumes aligned pairs and emits stitched outputs.
inference_fuse.py - Pipeline · Documents the intended end-to-end two-stage workflow.
main.sh
Data layer
Dataset contracts, manifests, and hyperparameter configs.
- Data cfgs · Dataset locations, splits, and manifests for the supported corpora.
data/udis.yaml - Hyperparams · Stage-specific optimization settings for scratch and finetune runs.
data/hyp.align.scratch.yaml
Model stack
Shared model framework and stage-specific network definitions.
- Align nets · Alignment model variants and backbone-scale settings.
models/align_yolo.yaml - Fuse nets · Fusion model variants and backbone-scale settings.
models/fuse_yolo.yaml - Model core · Shared YOLO-style modules and model parsing logic.
models/yolo.py - Blocks · Reusable neural network building blocks shared across variants.
models/common.py - Experimental · Auxiliary model components and variant layers.
models/experimental.py
Utility core
Losses, stitching, geometry, and runtime helpers.
- Losses · Training objectives for alignment and reconstruction.
utils/loss.py - Dataloader · Loads paired images, applies preprocessing, and builds minibatches.
utils/datasets.py - Stitching · Alignment, warping, and composition helpers.
utils/stitching.py - General utils · Shared evaluation and image-processing utilities.
utils/general.py - Torch utils · PyTorch device, precision, and execution helpers.
utils/torch_utils.py
Connections 27
- UDIS-D → Data cfgs: dataset paths · Dataset manifests point to UDIS-D splits.
- WarpedCOCO → Data cfgs: dataset paths · Dataset manifests point to WarpedCOCO splits.
- YOLO weights → Train: init · Pretrained weights initialize YOLO-backed variants.
- Data cfgs → Dataloader: load · Dataset config is converted into minibatches.
- Hyperparams → Train: optimize · Training uses stage-specific hyperparameters.
- Align nets → Train: align model · Alignment architecture is selected from YAML.
- Fuse nets → Train: fuse model · Fusion architecture is selected from YAML.
- Dataloader → Train: batches · Dataloader feeds training and validation batches.
- Model core → Align nets: assemble · Shared framework assembles alignment networks.
- Model core → Fuse nets: assemble · Shared framework assembles fusion networks.
- Blocks → Model core: blocks · Common modules provide reusable layers.
- Experimental → Model core: variants · Experimental components extend model definitions.
- Losses → Train: objective · Losses drive optimization in both stages.
- Stitching → Align infer: warp · Alignment inference produces warped pairs.
- Stitching → Fuse infer: compose · Fusion inference builds the final stitched image.
- General utils → Test: metrics · Evaluation utilities support metric computation.
- General utils → Align infer: eval · General helpers support alignment evaluation outputs.
- General utils → Fuse infer: eval · General helpers support fusion output handling.
- Torch utils → Train: runtime · PyTorch runtime helpers support training execution.
- Pipeline → Train: stage 1 · Workflow starts with alignment training.
- Pipeline → Align infer: stage 2 · Workflow runs alignment inference to produce warped pairs.
- Pipeline → Fuse infer: stage 3 · Workflow runs fusion on aligned pairs.
- Train → Align infer: checkpoint flow · Trained alignment weights are reused for inference.
- Align infer → Train: warped pairs · Aligned outputs feed the fusion training path.
- Align infer → Fuse infer: input pairs · Warped/aligned pairs become fusion inputs.
- Train → Fuse infer: checkpoint flow · Fusion training consumes stage-specific weights and aligned data.
- Test → General utils: reporting · Testing uses shared helpers for metrics and output handling.