Download scripts/artifixer_caption.py from kimjunhan/vkgs-sim: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/scripts/artifixer_caption.py
- Command line
-
hf download hf://kimjunhan/vkgs-sim/scripts/artifixer_caption.py
-
curl -L -o artifixer_caption.py https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/scripts/artifixer_caption.py
1.64 kB
| """ArtiFixer μΊ‘μ μλ² λ© (caption.h5) β artifixer νκ²½μμ μ€ννλ€ (UMT5-XXL ν μ€νΈ μΈμ½λ, CPU). | |
| ~/micromamba/envs/artifixer/bin/python scripts/artifixer_caption.py outputs/artifixer/<μ€λΉ λλ ν°λ¦¬> [...] | |
| νμμ artifixer data_processing/captioning/generate_captions.py μ κ°λ€: λ°μ΄ν°μ νλ = bf16 μλ² λ©μ uint16 μΌλ‘ λ³Έ λ°°μ΄ | |
| (ν ν° μ Γ 4096), attrs caption Β· image_indices. ν μ€νΈ μΈμ½λλ 22 GB(fp32 νμΌ) β bf16 μΌλ‘ CPU μ μ¬λ¦°λ€ (VRAM μ μ°μ§ μμ). | |
| """ | |
| import sys | |
| from pathlib import Path | |
| import h5py | |
| import torch | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT / "third_party/artifixer")) | |
| from data_processing.captioning.generate_captions import generate_text_embedding # noqa: E402 | |
| from transformers import AutoTokenizer, UMT5EncoderModel # noqa: E402 | |
| MODEL_ID = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers" | |
| def main(dirs: list[str]) -> None: | |
| tok = AutoTokenizer.from_pretrained(MODEL_ID, subfolder="tokenizer") | |
| enc = UMT5EncoderModel.from_pretrained(MODEL_ID, subfolder="text_encoder", torch_dtype=torch.bfloat16).eval() | |
| for d in map(Path, dirs): | |
| cap = (d / "caption.txt").read_text().strip() | |
| with torch.inference_mode(): | |
| emb = generate_text_embedding(cap, enc, tok, 512) | |
| with h5py.File(d / "caption.h5", "w") as hf: | |
| ds = hf.create_dataset("frames_0", data=emb) | |
| ds.attrs["caption"] = cap | |
| ds.attrs["image_indices"] = [0] | |
| print(f"{d / 'caption.h5'}: {emb.shape} β {cap[:60]}") | |
| if __name__ == "__main__": | |
| main(sys.argv[1:]) | |