Update r2c export helper
Browse files- scripts/export_r2c_layout.py +19 -5
scripts/export_r2c_layout.py
CHANGED
|
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
| 6 |
import argparse
|
| 7 |
import json
|
| 8 |
import shutil
|
|
|
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
from datasets import load_dataset, load_from_disk
|
|
@@ -47,10 +48,22 @@ def main() -> None:
|
|
| 47 |
f_out.write(line)
|
| 48 |
|
| 49 |
if args.local_stage_dir is None:
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
else:
|
| 55 |
local_ds = load_from_disk(args.local_stage_dir / "image_examples.dataset")
|
| 56 |
ds = {}
|
|
@@ -59,7 +72,8 @@ def main() -> None:
|
|
| 59 |
|
| 60 |
seen: set[str] = set()
|
| 61 |
for split_name, split_ds in ds.items():
|
| 62 |
-
|
|
|
|
| 63 |
img_fn = row["img_fn"]
|
| 64 |
metadata_fn = row["metadata_fn"]
|
| 65 |
|
|
|
|
| 6 |
import argparse
|
| 7 |
import json
|
| 8 |
import shutil
|
| 9 |
+
from itertools import islice
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
from datasets import load_dataset, load_from_disk
|
|
|
|
| 48 |
f_out.write(line)
|
| 49 |
|
| 50 |
if args.local_stage_dir is None:
|
| 51 |
+
if args.limit is None:
|
| 52 |
+
split_expr = {s: s for s in ("train", "validation", "test")}
|
| 53 |
+
ds = load_dataset(args.repo_id, "image_examples", split=split_expr, token=args.token)
|
| 54 |
+
if not isinstance(ds, dict):
|
| 55 |
+
ds = {"train": ds}
|
| 56 |
+
else:
|
| 57 |
+
ds = {
|
| 58 |
+
split_name: load_dataset(
|
| 59 |
+
args.repo_id,
|
| 60 |
+
"image_examples",
|
| 61 |
+
split=split_name,
|
| 62 |
+
streaming=True,
|
| 63 |
+
token=args.token,
|
| 64 |
+
)
|
| 65 |
+
for split_name in ("train", "validation", "test")
|
| 66 |
+
}
|
| 67 |
else:
|
| 68 |
local_ds = load_from_disk(args.local_stage_dir / "image_examples.dataset")
|
| 69 |
ds = {}
|
|
|
|
| 72 |
|
| 73 |
seen: set[str] = set()
|
| 74 |
for split_name, split_ds in ds.items():
|
| 75 |
+
rows = islice(split_ds, args.limit) if args.limit is not None else split_ds
|
| 76 |
+
for row in tqdm(rows, desc=f"export {split_name} images", total=args.limit):
|
| 77 |
img_fn = row["img_fn"]
|
| 78 |
metadata_fn = row["metadata_fn"]
|
| 79 |
|