File size: 5,924 Bytes
db75703 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | # GalaxyDiff Release
Self-contained **Measurement Alignment (MA)** inference package for conditional galaxy image generation.
Given 8 physical parameters, the package:
1. Samples a **64Γ64** image with a conditional diffusion model
2. Upscales to **224Γ224** with SwinIR
3. Measures the image with a **frozen** regression proxy
4. Reports consistency metrics (MAE / RMSE / MAE\(_z\))
All paths resolve under this folder (`Paper_code/GalaxyDiff_release/`). No external data download is required once `weights/` is present (~2.5β―GB).
---
## Pipeline
```
8-D conditions c
β
βΌ
CondNorm (z-score)
β
βΌ
MA diffusion βββΊ xββ βββΊ SwinIR SR βββΊ xβββ
β
βΌ
frozen Reg proxy R(Β·)
β
βΌ
Δ vs c
MAE / RMSE / MAE_z
```
---
## Layout
```
GalaxyDiff_release/
βββ generate_and_eval.py # CLI entry
βββ run.sh # one-command demo
βββ demo_generate_and_eval.ipynb
βββ README.md
βββ ma/ # release helpers
β βββ pipeline.py # end-to-end generate β SR β measure
β βββ cond.py # 8-D parse / CondNorm
β βββ joint_ckpt.py # load joint diffusion+SwinIR ckpt
β βββ ddim.py # fast sampling
β βββ sr.py # SwinIR wrap
β βββ metrics.py # MAE / RMSE / MAE_z
βββ vendor/ # model code only (no training)
β βββ Daldiff_cond_norm/
β βββ SwinIR-main/
β βββ Regression/
βββ weights/ # checkpoints (see MANIFEST.json)
β βββ 00003000-joint.pt
β βββ best_regression_head.pt
β βββ cond_norm_stats.json
β βββ backbone/ # DINOv3 + LoRA / LN finetune
βββ scripts/
β βββ assemble_bundle.sh # pull weights/vendor from this repo (once)
βββ runs/ # example outputs
```
---
## Quick start
```bash
cd /home/zhangbi/LJM/diffusion/Paper_code/GalaxyDiff_release
# If weights/ is empty, assemble once from the parent repo:
bash scripts/assemble_bundle.sh
# Demo (GPU 0)
bash run.sh
```
Or call the CLI directly:
```bash
CUDA_VISIBLE_DEVICES=0 python generate_and_eval.py \
--cond-values "0.0784,144.40,310.56,551.57,-0.3088,0.2504,5.1633,2.2935" \
--n-samples 4 \
--outdir runs/demo \
--sampling-timesteps 50
```
Interactive walkthrough: open `demo_generate_and_eval.ipynb` from this directory.
---
## CLI options
| Flag | Default | Meaning |
|------|---------|---------|
| `--cond-values` | *(required)* | 8 comma-separated floats (order below) |
| `--n-samples` | `4` | number of stochastic samples |
| `--outdir` | `runs/demo` | output directory |
| `--device` | `cuda` | `cuda` or `cpu` |
| `--rank` | `0` | GPU index for `DataParallel` |
| `--base-seed` | `42` | RNG seed for sampling |
| `--batch-size` | `4` | generation batch size |
| `--sampling-timesteps` | `50` | DDIM steps; `0` or `1000` β full 1000-step DDPM |
| `--mc-samples` | `10` | MC Dropout passes in the proxy |
| `--skip-generate` | off | reuse existing LR images in `outdir` |
| `--skip-sr` | off | skip SwinIR (LR-only path) |
`run.sh` env overrides: `COND_VALUES`, `N_SAMPLES`, `OUTDIR`, `SAMPLING_TIMESTEPS`, `MC_SAMPLES`, `CUDA_VISIBLE_DEVICES`.
---
## Input conditions (fixed order)
| # | Name | Meaning |
|---|------|---------|
| 1 | `redshift` | spectroscopic / photometric redshift |
| 2 | `flux_g` | g-band flux |
| 3 | `flux_r` | r-band flux |
| 4 | `flux_z` | z-band flux |
| 5 | `shape_e1` | ellipticity \(e_1\) |
| 6 | `shape_e2` | ellipticity \(e_2\) |
| 7 | `shape_r` | effective radius \(r_e\) |
| 8 | `sersic` | SΓ©rsic index |
Values are **physical units** (not z-scored). CondNorm stats live in `weights/cond_norm_stats.json`.
---
## Outputs (`--outdir`)
| Path | Content |
|------|---------|
| `lr/output/*.png` | generated 64Γ64 images |
| `sr/sr/*.png` | 224Γ224 super-resolved images |
| `param_comparison.csv` | input \(c\) vs measured \(\hat{c}\) |
| `summary.json` / `metrics.json` | MAE, RMSE, MAE\(_z\) (when \(N\ge 2\)) |
| `input_cond.json` | echo of the requested conditions |
---
## Weights
See `weights/MANIFEST.json`:
| File | Role |
|------|------|
| `00003000-joint.pt` | joint MA checkpoint (diffusion + SwinIR, step 3000) |
| `best_regression_head.pt` | frozen measurement proxy |
| `cond_norm_stats.json` | condition z-score mean / std |
| `backbone/dinov3-vitl16-β¦` | DINOv3 ViT-L/16 |
| `backbone/finetune_2addLN/` | LoRA + LN adapters for the proxy |
Approximate disk: **~2.5β―GB** under `weights/`.
---
## Assemble from this repository
Only needed if `weights/` or `vendor/` are missing (e.g. after a fresh clone without the bundle):
```bash
cd /home/zhangbi/LJM/diffusion/Paper_code/GalaxyDiff_release
bash scripts/assemble_bundle.sh
```
The script copies / hardlinks diffusion, SwinIR, and regression code from `diffusion_model/`, and checkpoints from related `Paper_code/experiment*` paths.
---
## Dependencies
```
torch
torchvision
transformers
timm
Pillow
numpy
pandas
matplotlib
tqdm
```
CUDA GPU recommended. Full DDPM (`--sampling-timesteps 0`) is much slower than DDIM 50.
---
## Notes
- This package is **inference-only**; training lives in `diffusin_model_fits/` and `diffusion_model/`.
- Folder was formerly named `model_release`; paths in older docs may still say that β use `GalaxyDiff_release` instead.
- Prefer `--sampling-timesteps 50` for demos; use `1000` / `0` only when comparing to paper-quality DDPM sampling.
|