text stringlengths 0 1.47k |
|---|
written atomically. |
""" |
extra = {v: load_json(pjoin(save_dir, f'captions_{v}.json')) |
for v in EXTRA_CAPTION_VERSIONS} |
total_filtered = sum(len(v) for v in all_filtered_clips.values()) |
with atomic_output_path(pjoin(save_dir, 'metadata.txt')) as tmp_path, \ |
open(tmp_path, 'w') as f: |
f.write(f'Total clips: {stats["total_clips"]}\n') |
f.write(f'Total frames: {stats["total_frames"]}\n') |
f.write(f'Total duration (minutes, assuming {stats.get("fps", 30)} fps): ' |
f'{stats["duration_min"]:.2f}\n') |
f.write(f'Max joints in dataset: {stats["max_njoints"]}\n') |
if all_captions is not None: |
f.write(f'Total captions: {len(all_captions)}\n') |
for version, caps in extra.items(): |
if caps is not None: |
f.write(f'Total {version} captions: {len(caps)}\n') |
f.write('Clips per object type:\n') |
for obj, count in stats['clips_per_object'].items(): |
f.write(f' {obj}: {count}\n') |
f.write('Joints per object type:\n') |
for obj, count in stats['joints_per_object'].items(): |
f.write(f' {obj}: {count}\n') |
f.write(f'Total filtered clips: {total_filtered}\n') |
if all_filtered_clips: |
f.write('Filtered clips per object type:\n') |
for obj, clips in all_filtered_clips.items(): |
f.write(f' {obj}: {len(clips)}\n') |
if category_groups: |
f.write('Categories:\n') |
for cat, members in category_groups.items(): |
processed = [m for m in members if m in stats['clips_per_object']] |
f.write(f' {cat}: {len(processed)} object types\n') |
# --------------------------------------------------------------------------- |
# Clip windowing |
# --------------------------------------------------------------------------- |
def compute_clip_windows(nframes, max_clip_len, clip_stride): |
"""Compute (start, end) windows for cropping a sequence into clips. |
Windows are ``max_clip_len`` frames long and start every ``clip_stride`` |
frames. No returned window is ever longer than ``max_clip_len`` (the whole |
sequence is returned unsliced only when it already fits). |
Leftover frames past the last strided window are handled by tail length, |
measured against the window overlap ``max_clip_len - clip_stride`` — the |
longest training crop the clips are cut to hold: |
- at least one full training crop: emitted as their own (shorter) |
trailing window, which is long enough to be croppable on its own; |
- shorter than that: covered by a full-length window anchored at the |
final frame, replacing the last window when the frames it gives up stay |
covered by the one before it (always true once there are two or more |
windows); |
- shorter than that and there is only one window to replace: dropped, |
rather than glued onto the previous window (which would push that clip |
past ``max_clip_len``) or duplicated as a near-copy of it. |
""" |
if not max_clip_len or nframes <= max_clip_len: |
return [(0, nframes)] |
clips = [] |
for start in range(0, nframes - max_clip_len + 1, clip_stride): |
clips.append((start, start + max_clip_len)) |
last_end = clips[-1][1] |
if last_end < nframes: |
tail_len = nframes - last_end |
# A trailing window earns its place once it can hold one full |
# training crop, i.e. the overlap a normal window is given. |
min_tail = max(1, max_clip_len - clip_stride) |
if tail_len >= min_tail: |
clips.append((last_end, nframes)) |
else: |
# Cover the tail with a full-length window anchored at the end. |
slid_start = nframes - max_clip_len |
prev_end = clips[-2][1] if len(clips) >= 2 else 0 |
if slid_start <= prev_end: |
# Free: the frames the last window gives up are still covered. |
clips[-1] = (slid_start, nframes) |
# Otherwise the tail is too small to pay for a window of its own. |
return clips |
def get_motion_clip_windows(nframes, max_clip_len, clip_stride, apply_clip=True): |
"""Return clip windows for a motion sequence. |
When ``apply_clip`` is True, crops into overlapping fixed-length clips via |
:func:`compute_clip_windows`. When False, returns a single window covering |
at most the first ``max_clip_len`` frames (i.e., truncation, not cropping). |
""" |
if apply_clip: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.