save original tile, SR in/out, OP masked-in/out to logs/
Browse files- example_sr_op.py +22 -10
example_sr_op.py
CHANGED
|
@@ -7,10 +7,18 @@ fetches one real Esri World Imagery tile (Sydney Opera House / Circular Quay,
|
|
| 7 |
zoom 16), then:
|
| 8 |
|
| 9 |
1. SR: the 256x256 parent tile (z16) -> 512x512 mosaic of its four z17
|
| 10 |
-
children in a single forward pass
|
| 11 |
2. OP: the tile viewed as a 2x2 quadrant mosaic (each quadrant is the
|
| 12 |
footprint of one real z17 child); keep the upper-left quadrant real,
|
| 13 |
-
outpaint the other three
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
Run from the root of a https://github.com/mvrl/genesis checkout,
|
| 16 |
with its environment active (`uv sync && source .venv/bin/activate`):
|
|
@@ -58,10 +66,13 @@ ARCH = "JiT-H/16" # main H/16 checkpoints (~49 GB download; set "JiT-B/16" for
|
|
| 58 |
# Fixed scenic spot: Sydney Opera House / Circular Quay waterfront.
|
| 59 |
LAT, LON, ZOOM = -33.8568, 151.2153, 16 # training zoom levels are 10..19
|
| 60 |
|
|
|
|
|
|
|
| 61 |
|
| 62 |
def main() -> None:
|
| 63 |
device = inference_device() # cuda if available, else cpu
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
# 1. Checkpoints from the HF Hub (cached under ~/.cache/huggingface).
|
| 67 |
# The main SR model is DINOv3-conditioned; the main OP model is no-DINO.
|
|
@@ -69,16 +80,17 @@ def main() -> None:
|
|
| 69 |
op_ckpt = hf_hub_download(HF_REPO, "main/outpainting/main_H16/op-new-stage3-step0800000.ckpt")
|
| 70 |
dino = hf_hub_download(HF_REPO, "dinov3_vitl16_pretrain_sat493m-eadcf0ff.pth")
|
| 71 |
|
| 72 |
-
# 2. One real 256x256 Esri World Imagery tile
|
| 73 |
tile = fetch_tile_at_zoom(LON, LAT, ZOOM) # PIL RGB, 256x256
|
| 74 |
-
tile.save("
|
| 75 |
|
| 76 |
# 3. Super-resolution: z16 parent -> 512x512 mosaic of its 4 z17 children.
|
| 77 |
# target_zoom is the CHILD zoom level (feeds the model's GSD embedder).
|
|
|
|
| 78 |
sr_model, _ = load_sr_denoiser(sr_ckpt, ARCH, dino_weights=dino, device=device)
|
| 79 |
sr_out = run_superresolution(sr_model, tile, device, target_zoom=ZOOM + 1)
|
| 80 |
-
sr_out.save("
|
| 81 |
-
print("
|
| 82 |
|
| 83 |
del sr_model # free memory before loading the OP model
|
| 84 |
if device.type == "cuda":
|
|
@@ -90,10 +102,10 @@ def main() -> None:
|
|
| 90 |
mask.paste(0, (0, 0, 128, 128)) # ... except the upper-left quadrant
|
| 91 |
|
| 92 |
op_model, _ = load_op_denoiser(op_ckpt, ARCH, dino_weights="", device=device)
|
| 93 |
-
outpaint_context_white_holes_preview(tile, mask).save("
|
| 94 |
op_out = run_outpainting(op_model, tile, mask, device, tile_zoom=ZOOM)
|
| 95 |
-
op_out.save("
|
| 96 |
-
print("
|
| 97 |
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
|
|
|
| 7 |
zoom 16), then:
|
| 8 |
|
| 9 |
1. SR: the 256x256 parent tile (z16) -> 512x512 mosaic of its four z17
|
| 10 |
+
children in a single forward pass
|
| 11 |
2. OP: the tile viewed as a 2x2 quadrant mosaic (each quadrant is the
|
| 12 |
footprint of one real z17 child); keep the upper-left quadrant real,
|
| 13 |
+
outpaint the other three
|
| 14 |
+
|
| 15 |
+
All inputs/outputs are saved to logs/example_sr_op/ (git-ignored):
|
| 16 |
+
|
| 17 |
+
01_original_tile.png the fetched Esri tile (input to both tasks)
|
| 18 |
+
02_sr_input.png SR input = the original 256x256 parent tile
|
| 19 |
+
03_sr_output.png SR output = 512x512 mosaic of its 4 children
|
| 20 |
+
04_op_masked_input.png OP input = 1 real quadrant, 3 white holes
|
| 21 |
+
05_op_output.png OP output = the 3 masked quadrants synthesized
|
| 22 |
|
| 23 |
Run from the root of a https://github.com/mvrl/genesis checkout,
|
| 24 |
with its environment active (`uv sync && source .venv/bin/activate`):
|
|
|
|
| 66 |
# Fixed scenic spot: Sydney Opera House / Circular Quay waterfront.
|
| 67 |
LAT, LON, ZOOM = -33.8568, 151.2153, 16 # training zoom levels are 10..19
|
| 68 |
|
| 69 |
+
OUT = os.path.join(REPO, "logs", "example_sr_op")
|
| 70 |
+
|
| 71 |
|
| 72 |
def main() -> None:
|
| 73 |
device = inference_device() # cuda if available, else cpu
|
| 74 |
+
os.makedirs(OUT, exist_ok=True)
|
| 75 |
+
print(f"Device: {device} | outputs -> {OUT}")
|
| 76 |
|
| 77 |
# 1. Checkpoints from the HF Hub (cached under ~/.cache/huggingface).
|
| 78 |
# The main SR model is DINOv3-conditioned; the main OP model is no-DINO.
|
|
|
|
| 80 |
op_ckpt = hf_hub_download(HF_REPO, "main/outpainting/main_H16/op-new-stage3-step0800000.ckpt")
|
| 81 |
dino = hf_hub_download(HF_REPO, "dinov3_vitl16_pretrain_sat493m-eadcf0ff.pth")
|
| 82 |
|
| 83 |
+
# 2. One real 256x256 Esri World Imagery tile — the input to BOTH tasks.
|
| 84 |
tile = fetch_tile_at_zoom(LON, LAT, ZOOM) # PIL RGB, 256x256
|
| 85 |
+
tile.save(f"{OUT}/01_original_tile.png")
|
| 86 |
|
| 87 |
# 3. Super-resolution: z16 parent -> 512x512 mosaic of its 4 z17 children.
|
| 88 |
# target_zoom is the CHILD zoom level (feeds the model's GSD embedder).
|
| 89 |
+
tile.save(f"{OUT}/02_sr_input.png")
|
| 90 |
sr_model, _ = load_sr_denoiser(sr_ckpt, ARCH, dino_weights=dino, device=device)
|
| 91 |
sr_out = run_superresolution(sr_model, tile, device, target_zoom=ZOOM + 1)
|
| 92 |
+
sr_out.save(f"{OUT}/03_sr_output.png")
|
| 93 |
+
print("SR done: 02_sr_input.png (256 parent) -> 03_sr_output.png (512 mosaic)")
|
| 94 |
|
| 95 |
del sr_model # free memory before loading the OP model
|
| 96 |
if device.type == "cuda":
|
|
|
|
| 102 |
mask.paste(0, (0, 0, 128, 128)) # ... except the upper-left quadrant
|
| 103 |
|
| 104 |
op_model, _ = load_op_denoiser(op_ckpt, ARCH, dino_weights="", device=device)
|
| 105 |
+
outpaint_context_white_holes_preview(tile, mask).save(f"{OUT}/04_op_masked_input.png")
|
| 106 |
op_out = run_outpainting(op_model, tile, mask, device, tile_zoom=ZOOM)
|
| 107 |
+
op_out.save(f"{OUT}/05_op_output.png")
|
| 108 |
+
print("OP done: 04_op_masked_input.png (1 real quadrant) -> 05_op_output.png (outpainted)")
|
| 109 |
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|