Upload configs/make_tomls.py with huggingface_hub
Browse files- configs/make_tomls.py +76 -0
configs/make_tomls.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Gera os TOMLs de cache e de treino a partir das views ja criadas.
|
| 3 |
+
|
| 4 |
+
Schema H3 atual: `target_video_directory` + `target_modalities`. As chaves
|
| 5 |
+
antigas (`video_directory`, `h3_target_mode`) sao rejeitadas com ValueError
|
| 6 |
+
pelo trainer, nao aceitas como alias.
|
| 7 |
+
|
| 8 |
+
Cache e treino compartilham fontes/areas/duracoes/caches; a UNICA diferenca e o
|
| 9 |
+
batch_size (alto no cache, obrigatoriamente 1 no treino).
|
| 10 |
+
"""
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
import argparse
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# Todas as views em 124 frames: minimo do H3 de 5 s respeitado (5,17 s e o
|
| 16 |
+
# primeiro valor do grid 17k+5 acima de 5 s) e igual ao regime de geracao alvo.
|
| 17 |
+
VIEWS = [
|
| 18 |
+
("v288", 512, 288, 124),
|
| 19 |
+
("v384", 640, 384, 124),
|
| 20 |
+
("v480", 832, 480, 124),
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
HEADER = """# Gerado por make_tomls.py — {kind}
|
| 24 |
+
[general]
|
| 25 |
+
caption_extension = ".txt"
|
| 26 |
+
batch_size = {batch}
|
| 27 |
+
enable_bucket = true
|
| 28 |
+
bucket_no_upscale = true
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
ENTRY = """
|
| 32 |
+
[[datasets]]
|
| 33 |
+
target_video_directory = "{videos}"
|
| 34 |
+
target_modalities = ["video"]
|
| 35 |
+
cache_directory = "{cache}"
|
| 36 |
+
resolution = [{w}, {h}]
|
| 37 |
+
source_fps = 24.0
|
| 38 |
+
frame_extraction = "full"
|
| 39 |
+
max_frames = {frames}
|
| 40 |
+
num_repeats = 1
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def build(views_root: Path, cache_root: Path, batch: int, kind: str, only: set[str] | None) -> str:
|
| 45 |
+
out = HEADER.format(kind=kind, batch=batch)
|
| 46 |
+
for name, w, h, frames in VIEWS:
|
| 47 |
+
if only and name not in only:
|
| 48 |
+
continue
|
| 49 |
+
videos = views_root / name
|
| 50 |
+
if not videos.is_dir() or not any(videos.glob("*.mp4")):
|
| 51 |
+
continue
|
| 52 |
+
out += ENTRY.format(videos=videos, cache=cache_root / name,
|
| 53 |
+
w=w, h=h, frames=frames)
|
| 54 |
+
return out
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def main() -> None:
|
| 58 |
+
ap = argparse.ArgumentParser()
|
| 59 |
+
ap.add_argument("--views", required=True, type=Path)
|
| 60 |
+
ap.add_argument("--cache", required=True, type=Path)
|
| 61 |
+
ap.add_argument("--out-dir", required=True, type=Path)
|
| 62 |
+
ap.add_argument("--prefix", default="dataset_smoothloopv3")
|
| 63 |
+
ap.add_argument("--cache-batch", type=int, default=24)
|
| 64 |
+
ap.add_argument("--only", default="", help="views separadas por virgula")
|
| 65 |
+
a = ap.parse_args()
|
| 66 |
+
|
| 67 |
+
only = {x for x in a.only.split(",") if x} or None
|
| 68 |
+
a.out_dir.mkdir(parents=True, exist_ok=True)
|
| 69 |
+
for kind, batch in (("cache", a.cache_batch), ("train", 1)):
|
| 70 |
+
path = a.out_dir / f"{a.prefix}_{kind}.toml"
|
| 71 |
+
path.write_text(build(a.views, a.cache, batch, kind, only), encoding="utf-8")
|
| 72 |
+
print(path)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
main()
|