How yuuiind/sar2optical works
Project Type & Purpose
• This is an open-source machine-learning tool—a PyTorch‐based conditional GAN (Pix2Pix) for translating SAR images to optical images.
• Core use cases: data download/prep, model training, evaluation, single-image inference, ONNX export, ONNX inference.
Main Architectural Components
A. External Services & Data Sources
– Kaggle API (sentinel1/sentinel2 dataset)
– Hugging Face or Kaggle model storage (for checkpoints)
B. Data Management
– utils/data_downloader.py (downloads raw imagery into /data/v_2)
– config.yaml + utils/config.py (drives paths, split modes)
– data/split.json (defines train/val/test IDs)
C. Data Pipeline
– src/dataset.py (PyTorch Dataset & DataLoader)
– src/utils.py (image transforms, augmentations)
D. Model Definition
– src/layers.py (custom conv/transpose blocks)
– src/networks.py (U-Net generator, PatchGAN discriminator)
– src/pix2pix.py (combines generator + discriminator modules)
E. Loss & Metrics
– src/loss.py (GAN loss, L1 loss)
– src/metric.py (PSNR, SSIM computations)
F. Training Workflow (train.py)
– Reads config → initializes Dataset, Model, Optimizers → trains loop → computes losses/metrics → saves checkpoints → dumps loss graphs (/data/plots)
G. Evaluation Workflow (test.py & notebooks)
– Loads checkpoints → runs on test split → computes & logs PSNR/SSIM → visualizes via Jupyter notebooks
H. Inference Workflow
– inference.py (single image → load generator → produce optical output → save)
I. ONNX Export & Inference
– torch2onnx.py (loads PyTorch generator checkpoint → exports ONNX with dynamic/static axes)
– onnx_inference.py (loads ONNX model → runs inference → saves output image)
J. Utilities
– utils/utils.py (helper routines—logging, file I/O)
Relationships & Data Flows
External Data Source → Data Downloader → /data/v_2
Config Manager → Data Pipeline & Training & Inference & Export components
Data Pipeline → Model Definition → Loss & Metrics → Training Workflow
Training Workflow → Checkpoint Store → Evaluation / Inference / Export
Checkpoint Store → Inference & ONNX Export → ONNX Model Store → ONNX Inference
Architectural Patterns & Principles
– Separation of concerns: data ingestion, model definition, training loop, evaluation, inference, export
– Config-driven orchestration (all scripts read from a single YAML)
– Modular code organization under src/ and utils/
Technologies & Frameworks to Annotate
– Python 3.x, PyTorch, TorchVision
– ONNX (opset 17), ONNX Runtime
– YAML (for config), JSON (split file)
– Kaggle API, Hugging Face Hub
– Jupyter Notebooks for exploratory training/evaluation