text
stringlengths
0
1.47k
return payload
logger.info(f'[{object_type}] cache invalidated (export NPZs or joint_names.json '
f'entry changed); re-processing')
return None
cached_params = payload.get('params') or {}
diff = ', '.join(
f'{k}: {cached_params.get(k, "<missing>")} -> {v}'
for k, v in sorted(params.items())
if cached_params.get(k, '<missing>') != v)
logger.info(f'[{object_type}] cache invalidated (settings changed: {diff}); '
f're-processing')
return None
def _prune_object_clips(save_dir, clip_prefix, prune_vis):
"""Delete the clip files a previous run wrote for this object type.
``process_object`` only ever writes, and the training loader enumerates
``motions/`` rather than ``captions.json``, so a clip that disappears from
an object (removed from the export, or newly listed in
``filtered_clips.txt``) would keep its stale
``motions/{object}-{motion}-{idx}.npz`` on disk and still be trained on.
Called only on a cache miss, i.e. right before the object is rewritten in
full. ``clip_prefix`` is ``"{object_type}-"`` (empty for mixamo, whose
single object type owns every file in the directory).
Previews are pruned only when the run regenerates them (``--vis``), so a
later ``--no-vis`` run does not throw away the MP4s an earlier one made.
"""
targets = [('motions', '.npz')] + ([('videos', '.mp4')] if prune_vis else [])
removed = 0
for sub, ext in targets:
directory = pjoin(save_dir, sub)
if not os.path.isdir(directory):
continue
for name in os.listdir(directory):
if name.startswith(clip_prefix) and name.endswith(ext):
try:
os.remove(pjoin(directory, name))
removed += 1
except OSError as e: # noqa: PERF203 — one bad file must not abort
logger.warning(f'Could not remove stale {sub}/{name}: {e}')
return removed
def _vis_record(save_vis, vis_ground):
"""The preview settings a cache entry records: None when the run made no
previews."""
return {'ground': bool(vis_ground)} if save_vis else None
def _previews_current(payload, save_dir, clip_prefix, vis_ground):
"""Whether a cached object's previews are the ones a ``--vis`` run with
*vis_ground* makes: the entry records previews made with that ground
setting (an entry that records none, or no settings at all, does not
qualify), and every clip of the object in ``motions/`` has its
``videos/<clip>.mp4``."""
record = payload.get('vis')
if not isinstance(record, dict) or record.get('ground') != bool(vis_ground):
return False
motions_dir, videos_dir = pjoin(save_dir, 'motions'), pjoin(save_dir, 'videos')
clips = [name[:-4] for name in (os.listdir(motions_dir) if os.path.isdir(motions_dir) else [])
if name.startswith(clip_prefix) and name.endswith('.npz')]
return all(os.path.isfile(pjoin(videos_dir, clip + '.mp4')) for clip in clips)
def _rebuild_dir(save_dir, object_type):
return pjoin(save_dir, f'.rebuild_{object_type}')
def _object_files(save_dir, object_type, clip_prefix):
"""``(subdir, name)`` of every output file of the object: its clips,
previews and T-pose image."""
files = []
for sub, ext in (('motions', '.npz'), ('videos', '.mp4')):
d = pjoin(save_dir, sub)
files += [(sub, name) for name in (os.listdir(d) if os.path.isdir(d) else [])
if name.startswith(clip_prefix) and name.endswith(ext)]
if os.path.isfile(pjoin(save_dir, 'tpose', f'{object_type}.png')):
files.append(('tpose', f'{object_type}.png'))
return files
def _rebuild_with_previews(object_type, task, clip_prefix, part_path, payload, vis):
"""Process a cached object again, with previews, into a temporary
directory beside the outputs; when every clip got its preview, swap its
files in and write its new cache entry.
The swap removes the cache entry first and moves the object's current
files into the temporary directory before the new ones go in, so an
error midway is undone (old files and entry restored) and a crash
midway leaves a miss, never an entry beside half-replaced files.
Returns ``('rebuilt', result)``; ``('kept', None)`` when the rebuild
failed and the cached files and entry are as before; or ``('lost',
error)`` when an undo failed too: the entry is then gone, so the next
run re-processes the object.
"""
save_dir = task['save_dir']