text
stringlengths
0
1.47k
+ ', '.join(sorted(failed_objects)))
all_captions = save_outputs(args.save_dir, cond, all_filtered_clips,
category_groups=category_groups,
extra_captions=extra_captions,
keep_category_groups=args.category_groups == '')
stats = build_stats(clips_per_object, joints_per_object, total_frames, max_njoints)
print_summary(stats)
save_metadata_report(args.save_dir, stats, all_filtered_clips,
all_captions=all_captions, category_groups=category_groups)
if args.save_glb:
# bpy only here, so the stage itself stays Blender-free.
from data_process.feature_extraction.canonical_assets import bake_canonical_assets
glb_counts = bake_canonical_assets(args.data_dir, args.save_dir,
assets_dir=args.canonical_assets_dir,
dataset_type=args.dataset_type)
if glb_counts['failed']:
logger.error(f"{glb_counts['failed']} canonical GLB(s) failed; see glb_errors/ in "
f"the canonical_assets directory (the features are complete)")
logger.info('Dataset processing complete.')
if __name__ == "__main__":
main(parse_args())
# ===== file: data_process/feature_extraction/metadata.py =====
"""Metadata I/O and clip windowing for the feature-extraction stage.
Loads the per-dataset JSON side files produced by the caption and
joint-annotation stages (``motion_captions.json``, ``category_groups.json``,
``clean_joint_names.json``, ``face_joint_names.json``, ...), provides
case-insensitive per-object lookups, writes the stage outputs (``cond.npy``,
``captions.json``, ``filtered_clips.json``, ``metadata.txt``) and computes
clip windows. Used by :mod:`data_process.feature_extraction.extract_features`.
"""
import json
import os
import tempfile
from contextlib import contextmanager
from os.path import join as pjoin
import numpy as np
# ---------------------------------------------------------------------------
# Atomic output writes
# ---------------------------------------------------------------------------
@contextmanager
def atomic_output_path(path):
# type: (str) -> Iterator[str]
"""Yield a temp path next to *path*, renamed into place on clean exit.
Stage outputs land at the end of runs that can take hours, so writing them
in place risks leaving a truncated ``cond.npy`` / ``captions.json`` behind
if the run is interrupted. Writers fill the yielded temp path instead; the
final ``os.replace`` is atomic, so readers see either the previous file or
the complete new one, and a failed write leaves the previous file intact.
"""
directory = os.path.dirname(os.path.abspath(path))
os.makedirs(directory, exist_ok=True)
fd, tmp_path = tempfile.mkstemp(
dir=directory, prefix=f'.{os.path.basename(path)}.', suffix='.tmp')
os.close(fd)
try:
yield tmp_path
os.replace(tmp_path, path)
except BaseException:
try:
os.remove(tmp_path)
except OSError:
pass
raise
def atomic_np_save(path, data):
# type: (str, object) -> None
"""``np.save`` *data* to *path* atomically (see :func:`atomic_output_path`)."""
with atomic_output_path(path) as tmp_path:
# Passing a file object keeps np.save from appending '.npy' to the
# temp name (it only does that for string paths).
with open(tmp_path, 'wb') as f:
np.save(f, data)
# ---------------------------------------------------------------------------
# JSON loading & metadata helpers
# ---------------------------------------------------------------------------
def load_json(path):
# type: (str) -> Optional[dict]
"""Load a JSON file if it exists, otherwise return None."""
if path and os.path.isfile(path):
with open(path, 'r') as f:
return json.load(f)
return None
def load_motion_captions(source_dir):