File size: 24,417 Bytes
afecaea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | #!/usr/bin/env python3
"""Convert DataDistillBed image folders and selected ResNet teachers to Parquet.
The conversion is byte-preserving: compressed image bytes and checkpoint bytes are
stored directly in binary Parquet columns. The script validates the exact physical
image counts found during the archive audit and records SHA-256 digests for every
payload and output shard.
"""
from __future__ import annotations
import argparse
import collections
import datetime as dt
import hashlib
import json
import os
import re
import tarfile
from pathlib import Path, PurePosixPath
from typing import Any, Iterable
import pyarrow as pa
import pyarrow.parquet as pq
DATASET_ALIASES = {
"cifar10": "CIFAR-10",
"cifar100": "CIFAR-100",
"tiny": "TinyImageNet-200",
"imagenette": "ImageNette",
"imagenette128": "ImageNette",
"imagenet": "ImageNet-1K",
}
NUM_CLASSES = {
"CIFAR-10": 10,
"CIFAR-100": 100,
"TinyImageNet-200": 200,
"ImageNette": 10,
"ImageNet-1K": 1000,
}
STANDARD_GROUPS = {
"DC": {"CIFAR-10": (1, 10, 50), "CIFAR-100": (1, 10, 50)},
"DM": {"CIFAR-10": (1, 10, 50), "CIFAR-100": (1, 10, 50)},
"DSA": {"CIFAR-10": (1, 10, 50), "CIFAR-100": (1, 10, 50)},
"ATT": {
"CIFAR-10": (1, 10, 50),
"CIFAR-100": (1, 10, 50),
"TinyImageNet-200": (1, 10, 50),
"ImageNette": (1, 10),
},
"MTT": {
"CIFAR-10": (1, 10, 50),
"CIFAR-100": (1, 10, 50),
"TinyImageNet-200": (1, 10, 50),
"ImageNette": (1, 10),
},
"TESLA": {
"CIFAR-10": (1, 10, 50),
"CIFAR-100": (1, 10, 50),
"TinyImageNet-200": (1, 10, 50),
"ImageNette": (1, 10),
},
"CVDD": {
"CIFAR-10": (1, 10, 50),
"CIFAR-100": (1, 10, 50),
"TinyImageNet-200": (1, 10, 50),
"ImageNette": (1, 10, 50),
"ImageNet-1K": (1, 10, 50),
},
"GVBSM": {
"CIFAR-10": (1, 10, 50),
"CIFAR-100": (1, 10, 50),
"TinyImageNet-200": (1, 10, 50),
"ImageNet-1K": (1, 10, 50),
},
"SCDD": {"CIFAR-10": (1, 10, 50), "CIFAR-100": (1, 10, 50)},
"SRe2L": {
"TinyImageNet-200": (1, 10, 50),
"ImageNet-1K": (1, 10, 50),
},
"WMDD": {
"TinyImageNet-200": (1, 10, 50),
"ImageNette": (10, 50),
"ImageNet-1K": (1, 10, 50),
},
}
FRED_COUNTS = {
("CIFAR-10", 1): 160,
("CIFAR-10", 10): 640,
("CIFAR-10", 50): 2000,
("CIFAR-100", 1): 800,
("CIFAR-100", 10): 1000,
("CIFAR-100", 50): 5000,
("TinyImageNet-200", 1): 1600,
("ImageNette", 1): 80,
("ImageNette", 10): 400,
}
NCFM_GROUPS = {
"CIFAR-10": (1, 10, 50),
"CIFAR-100": (1, 10, 50),
"TinyImageNet-200": (1, 10, 50),
"ImageNette": (1, 10, 50),
}
TEACHERS = {
"other_pretrained_models/CVDD/cifar10/ResNet18.pth": {
"provider": "CVDD",
"dataset": "CIFAR-10",
"architecture": "ResNet18",
"used_by": ["CVDD"],
},
"other_pretrained_models/CVDD/cifar100/ResNet18.pth": {
"provider": "CVDD",
"dataset": "CIFAR-100",
"architecture": "ResNet18",
"used_by": ["CVDD"],
},
"other_pretrained_models/GVBSM/CIFAR-10/ResNet18/squeeze_ResNet18.pth": {
"provider": "GVBSM",
"dataset": "CIFAR-10",
"architecture": "ResNet18",
"used_by": ["GVBSM"],
},
"other_pretrained_models/GVBSM/CIFAR-100/ResNet18/squeeze_ResNet18.pth": {
"provider": "GVBSM",
"dataset": "CIFAR-100",
"architecture": "ResNet18",
"used_by": ["GVBSM"],
},
"other_pretrained_models/WMDD/tiny-imagenet_model_49.pth": {
"provider": "WMDD",
"dataset": "TinyImageNet-200",
"architecture": "ResNet18",
"used_by": ["WMDD"],
},
"other_pretrained_models/WMDD/imagenette_model_49.pth": {
"provider": "WMDD",
"dataset": "ImageNette",
"architecture": "ResNet18",
"used_by": ["WMDD"],
},
}
MISSING_TEACHERS = [
"other_pretrained_models/GVBSM/tiny/ResNet18/squeeze_ResNet18.pth",
"other_pretrained_models/SRe2L/cifar10/ckpt.pth",
"other_pretrained_models/SRe2L/cifar100/ckpt.pth",
"torchvision official ResNet-18 checkpoint (runtime dependency)",
]
IMAGE_SCHEMA = pa.schema(
[
pa.field("method", pa.string(), nullable=False),
pa.field("dataset", pa.string(), nullable=False),
pa.field("ipc", pa.int32(), nullable=False),
pa.field("class_id", pa.int32(), nullable=False),
pa.field("image_id", pa.int32(), nullable=False),
pa.field("source_path", pa.string(), nullable=False),
pa.field("extension", pa.string(), nullable=False),
pa.field(
"image",
pa.struct(
[
pa.field("bytes", pa.binary(), nullable=False),
pa.field("path", pa.string(), nullable=False),
]
),
nullable=False,
),
pa.field("sample_weight", pa.float64()),
pa.field("sha256", pa.string(), nullable=False),
pa.field("byte_size", pa.int64(), nullable=False),
pa.field("source_archive", pa.string(), nullable=False),
]
)
TEACHER_SCHEMA = pa.schema(
[
pa.field("provider", pa.string(), nullable=False),
pa.field("dataset", pa.string(), nullable=False),
pa.field("architecture", pa.string(), nullable=False),
pa.field("used_by", pa.list_(pa.string()), nullable=False),
pa.field("source_path", pa.string(), nullable=False),
pa.field("checkpoint", pa.binary(), nullable=False),
pa.field("sha256", pa.string(), nullable=False),
pa.field("byte_size", pa.int64(), nullable=False),
pa.field("source_archive", pa.string(), nullable=False),
]
)
SHARD_SCHEMA = pa.schema(
[
pa.field("asset_type", pa.string(), nullable=False),
pa.field("relative_path", pa.string(), nullable=False),
pa.field("method_or_provider", pa.string(), nullable=False),
pa.field("row_count", pa.int64(), nullable=False),
pa.field("payload_bytes", pa.int64(), nullable=False),
pa.field("parquet_bytes", pa.int64(), nullable=False),
pa.field("sha256", pa.string(), nullable=False),
]
)
def sha256_file(path: Path, chunk_size: int = 8 * 1024 * 1024) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
while chunk := handle.read(chunk_size):
digest.update(chunk)
return digest.hexdigest()
def normalized_tar_path(name: str) -> str:
value = name.replace("\\", "/")
while value.startswith("./"):
value = value[2:]
return value
def parse_image_path(name: str) -> tuple[str, int, int, int, str]:
normalized = normalized_tar_path(name)
parts = PurePosixPath(normalized).parts
dataset = next(
(DATASET_ALIASES[p.lower()] for p in parts if p.lower() in DATASET_ALIASES),
None,
)
ipc_token = next((p for p in parts if re.fullmatch(r"ipc\d+", p.lower())), None)
class_token = next((p for p in parts if re.fullmatch(r"new\d+", p.lower())), None)
if dataset is None or ipc_token is None or class_token is None:
raise ValueError(f"Cannot parse dataset/ipc/class from {normalized!r}")
ipc = int(ipc_token[3:])
class_id = int(class_token[3:])
filename = parts[-1]
explicit = re.search(r"class(\d+)_id(\d+)", filename, flags=re.IGNORECASE)
generic = re.search(r"image_(\d+)", filename, flags=re.IGNORECASE)
if explicit:
filename_class = int(explicit.group(1))
if filename_class != class_id:
raise ValueError(
f"Directory class {class_id} disagrees with filename class "
f"{filename_class}: {normalized}"
)
image_id = int(explicit.group(2))
elif generic:
image_id = int(generic.group(1))
else:
raise ValueError(f"Cannot parse image id from {normalized!r}")
extension = Path(filename).suffix.lower()
if extension not in {".jpg", ".jpeg", ".png"}:
raise ValueError(f"Unsupported image extension in {normalized!r}")
return dataset, ipc, class_id, image_id, extension
def expected_physical_counts() -> dict[tuple[str, str, int], int]:
result: dict[tuple[str, str, int], int] = {}
for method, datasets in STANDARD_GROUPS.items():
for dataset, ipcs in datasets.items():
for ipc in ipcs:
result[(method, dataset, ipc)] = NUM_CLASSES[dataset] * ipc
for (dataset, ipc), count in FRED_COUNTS.items():
result[("FreD", dataset, ipc)] = count
for dataset, ipcs in NCFM_GROUPS.items():
for ipc in ipcs:
result[("NCFM", dataset, ipc)] = NUM_CLASSES[dataset] * ipc * 4
return result
def load_wmdd_weights(archive: Path) -> dict[tuple[str, int], list[list[float]]]:
result: dict[tuple[str, int], list[list[float]]] = {}
with tarfile.open(archive, "r:gz") as tf:
for member in tf:
if not member.isfile() or not member.name.endswith("sample_weights.txt"):
continue
dataset, ipc, _, _, _ = parse_weight_path(member.name)
extracted = tf.extractfile(member)
if extracted is None:
raise RuntimeError(f"Cannot extract {member.name}")
lines = extracted.read().decode("utf-8").splitlines()
matrix = [[float(value) for value in line.split()] for line in lines]
if len(matrix) != NUM_CLASSES[dataset]:
raise ValueError(f"Wrong class count in {member.name}: {len(matrix)}")
if any(len(row) != ipc for row in matrix):
raise ValueError(f"Wrong IPC width in {member.name}")
result[(dataset, ipc)] = matrix
return result
def parse_weight_path(name: str) -> tuple[str, int, int, int, str]:
normalized = normalized_tar_path(name)
parts = PurePosixPath(normalized).parts
dataset = next(
(DATASET_ALIASES[p.lower()] for p in parts if p.lower() in DATASET_ALIASES),
None,
)
ipc_token = next((p for p in parts if re.fullmatch(r"ipc\d+", p.lower())), None)
if dataset is None or ipc_token is None:
raise ValueError(f"Cannot parse WMDD weight path {normalized!r}")
return dataset, int(ipc_token[3:]), 0, 0, ".txt"
class ImageShardWriter:
def __init__(self, root: Path, method: str, target_bytes: int, batch_size: int):
self.root = root
self.method = method
self.target_bytes = target_bytes
self.batch_size = batch_size
self.shard_index = -1
self.writer: pq.ParquetWriter | None = None
self.path: Path | None = None
self.rows: list[dict[str, Any]] = []
self.rows_in_shard = 0
self.payload_in_shard = 0
self.records: list[dict[str, Any]] = []
def _open(self) -> None:
self.shard_index += 1
directory = self.root / "data" / "images" / self.method
directory.mkdir(parents=True, exist_ok=True)
self.path = directory / f"train-{self.shard_index:05d}.parquet"
if self.path.exists():
raise FileExistsError(f"Refusing to overwrite {self.path}")
self.writer = pq.ParquetWriter(
self.path,
IMAGE_SCHEMA,
compression="zstd",
compression_level=3,
use_dictionary=["method", "dataset", "extension", "source_archive"],
write_statistics=[
"method",
"dataset",
"ipc",
"class_id",
"image_id",
"sample_weight",
"byte_size",
],
data_page_size=1024 * 1024,
)
def _flush_rows(self) -> None:
if not self.rows:
return
assert self.writer is not None
table = pa.Table.from_pylist(self.rows, schema=IMAGE_SCHEMA)
self.writer.write_table(table, row_group_size=self.batch_size)
self.rows.clear()
def _close(self) -> None:
if self.writer is None or self.path is None:
return
self._flush_rows()
self.writer.close()
parquet_file = pq.ParquetFile(self.path)
if parquet_file.metadata.num_rows != self.rows_in_shard:
raise RuntimeError(f"Row-count mismatch in {self.path}")
self.records.append(
{
"asset_type": "image",
"relative_path": self.path.relative_to(self.root).as_posix(),
"method_or_provider": self.method,
"row_count": self.rows_in_shard,
"payload_bytes": self.payload_in_shard,
"parquet_bytes": self.path.stat().st_size,
"sha256": sha256_file(self.path),
}
)
self.writer = None
self.path = None
self.rows_in_shard = 0
self.payload_in_shard = 0
def append(self, row: dict[str, Any]) -> None:
payload_size = int(row["byte_size"])
if self.writer is None:
self._open()
elif self.rows_in_shard and self.payload_in_shard + payload_size > self.target_bytes:
self._close()
self._open()
self.rows.append(row)
self.rows_in_shard += 1
self.payload_in_shard += payload_size
if len(self.rows) >= self.batch_size:
self._flush_rows()
def close(self) -> list[dict[str, Any]]:
self._close()
return self.records
def convert_images(
inner_root: Path, output_root: Path, target_bytes: int, batch_size: int
) -> tuple[list[dict[str, Any]], dict[tuple[str, str, int], int], int, int]:
expected = expected_physical_counts()
observed: collections.Counter[tuple[str, str, int]] = collections.Counter()
class_ids: dict[tuple[str, str, int], set[int]] = collections.defaultdict(set)
shard_records: list[dict[str, Any]] = []
total_payload = 0
total_rows = 0
archives = sorted(inner_root.glob("*.tar.gz"))
archive_methods = {path.name.removesuffix(".tar.gz") for path in archives}
expected_methods = set(STANDARD_GROUPS) | {"FreD", "NCFM"}
if archive_methods != expected_methods:
raise ValueError(
f"Method archives differ from checklist: found={sorted(archive_methods)}, "
f"expected={sorted(expected_methods)}"
)
for archive in archives:
method = archive.name.removesuffix(".tar.gz")
print(f"[images] {method}: reading {archive.name}", flush=True)
weights = load_wmdd_weights(archive) if method == "WMDD" else {}
writer = ImageShardWriter(output_root, method, target_bytes, batch_size)
with tarfile.open(archive, "r:gz") as tf:
for member in tf:
if not member.isfile():
continue
normalized = normalized_tar_path(member.name)
suffix = Path(normalized).suffix.lower()
if suffix == ".txt" and normalized.endswith("sample_weights.txt"):
if method != "WMDD":
raise ValueError(f"Unexpected sample weights outside WMDD: {normalized}")
continue
if suffix not in {".jpg", ".jpeg", ".png"}:
raise ValueError(f"Unexpected non-image file in {archive.name}: {normalized}")
dataset, ipc, class_id, image_id, extension = parse_image_path(normalized)
key = (method, dataset, ipc)
if key not in expected:
raise ValueError(f"Image group is not in the checklist: {key}")
if class_id < 0 or class_id >= NUM_CLASSES[dataset]:
raise ValueError(f"Class id outside range in {normalized}")
extracted = tf.extractfile(member)
if extracted is None:
raise RuntimeError(f"Cannot extract {normalized}")
payload = extracted.read()
if len(payload) != member.size:
raise RuntimeError(
f"Short read for {normalized}: {len(payload)} != {member.size}"
)
sample_weight = None
if method == "WMDD":
matrix = weights.get((dataset, ipc))
if matrix is None:
raise ValueError(f"Missing WMDD weights for {dataset} IPC {ipc}")
if image_id < 0 or image_id >= ipc:
raise ValueError(f"WMDD image id outside IPC range: {normalized}")
sample_weight = matrix[class_id][image_id]
writer.append(
{
"method": method,
"dataset": dataset,
"ipc": ipc,
"class_id": class_id,
"image_id": image_id,
"source_path": normalized,
"extension": extension,
"image": {"bytes": payload, "path": normalized},
"sample_weight": sample_weight,
"sha256": hashlib.sha256(payload).hexdigest(),
"byte_size": len(payload),
"source_archive": archive.name,
}
)
observed[key] += 1
class_ids[key].add(class_id)
total_rows += 1
total_payload += len(payload)
shard_records.extend(writer.close())
method_rows = sum(value for key, value in observed.items() if key[0] == method)
print(f"[images] {method}: wrote {method_rows:,} rows", flush=True)
if dict(observed) != expected:
missing = {key: value for key, value in expected.items() if observed.get(key) != value}
extra = {key: value for key, value in observed.items() if expected.get(key) != value}
raise ValueError(f"Physical count validation failed; expected-diff={missing}, observed-diff={extra}")
for key in sorted(expected):
required = set(range(NUM_CLASSES[key[1]]))
if class_ids[key] != required:
raise ValueError(f"Class coverage validation failed for {key}")
return shard_records, dict(observed), total_rows, total_payload
def teacher_filename(spec: dict[str, Any]) -> str:
values = [spec["provider"], spec["dataset"], spec["architecture"]]
return "-".join(re.sub(r"[^A-Za-z0-9]+", "-", value).strip("-") for value in values).lower()
def convert_teachers(
archive: Path, output_root: Path
) -> tuple[list[dict[str, Any]], list[dict[str, Any]], int]:
output_dir = output_root / "data" / "teachers"
output_dir.mkdir(parents=True, exist_ok=True)
found: dict[str, dict[str, Any]] = {}
shard_records: list[dict[str, Any]] = []
total_payload = 0
with tarfile.open(archive, "r:") as tf:
for member in tf:
if not member.isfile():
continue
normalized = normalized_tar_path(member.name)
spec = TEACHERS.get(normalized)
if spec is None:
continue
extracted = tf.extractfile(member)
if extracted is None:
raise RuntimeError(f"Cannot extract {normalized}")
payload = extracted.read()
if len(payload) != member.size:
raise RuntimeError(f"Short read for {normalized}")
digest = hashlib.sha256(payload).hexdigest()
output = output_dir / f"{teacher_filename(spec)}.parquet"
if output.exists():
raise FileExistsError(f"Refusing to overwrite {output}")
row = {
**spec,
"source_path": normalized,
"checkpoint": payload,
"sha256": digest,
"byte_size": len(payload),
"source_archive": archive.name,
}
table = pa.Table.from_pylist([row], schema=TEACHER_SCHEMA)
pq.write_table(
table,
output,
compression="zstd",
compression_level=1,
use_dictionary=["provider", "dataset", "architecture", "source_archive"],
write_statistics=["provider", "dataset", "architecture", "byte_size"],
data_page_size=1024 * 1024,
)
check = pq.read_table(output, columns=["sha256", "byte_size"]).to_pylist()[0]
if check["sha256"] != digest or check["byte_size"] != len(payload):
raise RuntimeError(f"Teacher Parquet verification failed for {output}")
found[normalized] = {key: value for key, value in row.items() if key != "checkpoint"}
total_payload += len(payload)
shard_records.append(
{
"asset_type": "teacher",
"relative_path": output.relative_to(output_root).as_posix(),
"method_or_provider": spec["provider"],
"row_count": 1,
"payload_bytes": len(payload),
"parquet_bytes": output.stat().st_size,
"sha256": sha256_file(output),
}
)
print(f"[teacher] {normalized}: {len(payload):,} bytes", flush=True)
missing_present = sorted(set(TEACHERS) - set(found))
if missing_present:
raise ValueError(f"Checklist says teacher exists but archive lookup failed: {missing_present}")
return shard_records, [found[path] for path in TEACHERS], total_payload
def write_manifest(output_root: Path, records: Iterable[dict[str, Any]]) -> None:
manifest_dir = output_root / "data" / "manifest"
manifest_dir.mkdir(parents=True, exist_ok=True)
output = manifest_dir / "shards.parquet"
if output.exists():
raise FileExistsError(f"Refusing to overwrite {output}")
table = pa.Table.from_pylist(list(records), schema=SHARD_SCHEMA)
pq.write_table(table, output, compression="zstd", compression_level=3)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--inner-root", required=True, type=Path)
parser.add_argument("--teacher-archive", required=True, type=Path)
parser.add_argument("--output-root", required=True, type=Path)
parser.add_argument("--target-shard-mib", type=int, default=450)
parser.add_argument("--batch-size", type=int, default=512)
args = parser.parse_args()
data_root = args.output_root / "data"
if data_root.exists() and any(data_root.rglob("*.parquet")):
raise FileExistsError(
f"Parquet output already exists under {data_root}; refusing to overwrite"
)
args.output_root.mkdir(parents=True, exist_ok=True)
image_shards, counts, image_rows, image_payload = convert_images(
args.inner_root,
args.output_root,
args.target_shard_mib * 1024 * 1024,
args.batch_size,
)
teacher_shards, teachers, teacher_payload = convert_teachers(
args.teacher_archive, args.output_root
)
all_shards = image_shards + teacher_shards
write_manifest(args.output_root, all_shards)
summary = {
"created_at_utc": dt.datetime.now(dt.timezone.utc).isoformat(),
"format": "byte-preserving Parquet",
"image_schema": str(IMAGE_SCHEMA),
"teacher_schema": str(TEACHER_SCHEMA),
"image_rows": image_rows,
"image_payload_bytes": image_payload,
"teacher_rows": len(teachers),
"teacher_payload_bytes": teacher_payload,
"image_group_counts": [
{"method": key[0], "dataset": key[1], "ipc": key[2], "rows": value}
for key, value in sorted(counts.items())
],
"teachers_present": teachers,
"teachers_missing_from_source_archives": MISSING_TEACHERS,
"shards": all_shards,
}
summary_path = args.output_root / "conversion_summary.json"
summary_path.write_text(json.dumps(summary, ensure_ascii=False, indent=2), encoding="utf-8")
print(
f"[done] images={image_rows:,} ({image_payload:,} bytes), "
f"teachers={len(teachers)} ({teacher_payload:,} bytes), "
f"shards={len(all_shards)}",
flush=True,
)
if __name__ == "__main__":
main()
|