text
stringlengths
0
1.47k
return _resolve_skip_list_path(path, data_dir, 'filtered_objects.txt')
def resolve_filtered_clips_path(path, data_dir):
return _resolve_skip_list_path(path, data_dir, 'filtered_clips.txt')
def resolve_clip_trims_path(path, data_dir):
return _resolve_skip_list_path(path, data_dir, 'clip_trims.txt')
def resolve_activity_keep_path(path, data_dir):
return _resolve_skip_list_path(path, data_dir, 'activity_keep.txt')
def resolve_extra_captions(path, data_dir, version):
"""Load the *version* captions named by ``--<version>_captions`` (or None).
``"auto"`` uses ``<data_dir>/motion_captions_<version>.json`` when present
and an empty string disables them; both then remove a stale
``captions_<version>.json``. An explicit path that does not exist raises
instead: a typo must not silently delete the captions already in the
feature directory.
"""
name = f'motion_captions_{version}.json'
if path == 'auto':
path = pjoin(data_dir, name)
if not os.path.isfile(path):
logger.info(f'No {name} in {data_dir}; no captions_{version}.json this run')
return None
elif not path:
return None
elif not os.path.isfile(path):
raise FileNotFoundError(f'--{version}_captions {path!r} does not exist')
captions = load_json(path)
logger.info(f'{version.capitalize()} captions: {len(captions)} from {path}')
return captions
def load_clip_trims(path):
"""Read ``<clip stem> <N>`` head trims; a falsy path yields an empty dict.
Malformed lines raise instead of being skipped: a trim that silently does
nothing would leave the snap it was written for in the training data.
"""
trims = {}
if not path:
return trims
with open(path, 'r') as f:
for lineno, line in enumerate(f, 1):
body = line.split('#', 1)[0].split()
if not body:
continue
if len(body) != 2 or not body[1].isdigit() or int(body[1]) < 1:
raise ValueError(f'{path}:{lineno}: expected "<clip stem> <N>" with '
f'N >= 1, got {line.strip()!r}')
trims[body[0]] = int(body[1])
return trims
def resolve_category_groups(path, metadata):
"""Return the category groups to copy into the feature dir, or None.
``"auto"`` (the default) keeps whatever ``load_all_metadata`` found in
the data dir; an empty string drops it; any other value is loaded as an
explicit path. Nothing in this stage consumes the groups — they are
passed through to the feature dir — so dropping them only means the
copy is made later, by hand, once the classifier has finished. Like the
two skip lists, a missing explicit path is skipped with a warning rather
than aborting the run.
"""
if not path:
if metadata.pop('category_groups', None) is not None:
logger.info('Ignoring category_groups.json (--category_groups="")')
return None
if path != 'auto':
groups = load_json(path)
if groups is None:
logger.warning(f'--category_groups {path!r} not found; the feature '
f'dir will get no category_groups.json')
metadata.pop('category_groups', None)
return None
metadata['category_groups'] = groups
return metadata.get('category_groups')
def load_filtered_objects(path):
"""Read a skip list; a falsy path (no file) yields an empty set."""
if not path:
return set()
with open(path, 'r') as f:
# one entry per line; blank lines and '#' comments (whole-line or
# trailing, e.g. "<uuid> # bone/bone pair") are ignored
entries = (line.split('#', 1)[0].strip() for line in f)
return {e for e in entries if e}
def discover_object_types(motion_dir, dataset_type, args):
"""Return (object_types, all_motions) given the dataset layout.