Buckets:

Mercity/FluxDistill / scripts /33_extract_ref.py
Pranav2748's picture
download
raw
838 Bytes
"""Extract matched MJHQ real images for the sampled prompts (FID-vs-real), resized to RES.
Usage: python3 scripts/33_extract_ref.py [RES] [N]
"""
import sys, json, os, io, zipfile
from PIL import Image
RES = int(sys.argv[1]) if len(sys.argv) > 1 else 512
N = int(sys.argv[2]) if len(sys.argv) > 2 else 10**9
sel = json.load(open('outputs/eval/prompts.json'))[:N]
z = zipfile.ZipFile('data/mjhq_raw/mjhq30k_imgs.zip')
out = 'outputs/eval/imgs/mjhq_ref'; os.makedirs(out, exist_ok=True)
n = 0
for d in sel:
arc = f"{d['category']}/{d['id']}.jpg"
try:
b = z.read(arc)
except KeyError:
print("missing", arc); continue
Image.open(io.BytesIO(b)).convert('RGB').resize((RES, RES), Image.LANCZOS).save(
f"{out}/{d['idx']:05d}.jpg", quality=95)
n += 1
print(f"extracted {n} ref imgs @ {RES} -> {out}")

Xet Storage Details

Size:
838 Bytes
·
Xet hash:
2ccf895c87d1b4178c06ab7eff6347292de5e14af3c29a5d9c98ea9ee188ba15

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.