MCPcopy Create free account
hub / github.com/Walter0807/MotionBERT / resample

Function resample

lib/utils/utils_data.py:68–89  ·  view source on GitHub ↗
(ori_len, target_len, replay=False, randomness=True)

Source from the content-addressed store, hash-verified

66 return flipped_data
67
68def resample(ori_len, target_len, replay=False, randomness=True):
69 if replay:
70 if ori_len > target_len:
71 st = np.random.randint(ori_len-target_len)
72 return range(st, st+target_len) # Random clipping from sequence
73 else:
74 return np.array(range(target_len)) % ori_len # Replay padding
75 else:
76 if randomness:
77 even = np.linspace(0, ori_len, num=target_len, endpoint=False)
78 if ori_len < target_len:
79 low = np.floor(even)
80 high = np.ceil(even)
81 sel = np.random.randint(2, size=even.shape)
82 result = np.sort(sel*low+(1-sel)*high)
83 else:
84 interval = even[1] - even[0]
85 result = np.random.random(even.shape)*interval + even
86 result = np.clip(result, a_min=0, a_max=ori_len-1).astype(np.uint32)
87 else:
88 result = np.linspace(0, ori_len, num=target_len, endpoint=False, dtype=int)
89 return result
90
91def split_clips(vid_list, n_frames, data_stride):
92 result = []

Callers 2

__init__Method · 0.90
split_clipsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected