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

Function crop_scale

lib/utils/utils_data.py:7–29  ·  view source on GitHub ↗

Motion: [(M), T, 17, 3]. Normalize to [-1, 1]

(motion, scale_range=[1, 1])

Source from the content-addressed store, hash-verified

5import copy
6
7def crop_scale(motion, scale_range=[1, 1]):
8 '''
9 Motion: [(M), T, 17, 3].
10 Normalize to [-1, 1]
11 '''
12 result = copy.deepcopy(motion)
13 valid_coords = motion[motion[..., 2]!=0][:,:2]
14 if len(valid_coords) < 4:
15 return np.zeros(motion.shape)
16 xmin = min(valid_coords[:,0])
17 xmax = max(valid_coords[:,0])
18 ymin = min(valid_coords[:,1])
19 ymax = max(valid_coords[:,1])
20 ratio = np.random.uniform(low=scale_range[0], high=scale_range[1], size=1)[0]
21 scale = max(xmax-xmin, ymax-ymin) * ratio
22 if scale==0:
23 return np.zeros(motion.shape)
24 xs = (xmin+xmax-scale) / 2
25 ys = (ymin+ymax-scale) / 2
26 result[...,:2] = (motion[..., :2]- [xs,ys]) / scale
27 result[...,:2] = (result[..., :2] - 0.5) * 2
28 result = np.clip(result, -1, 1)
29 return result
30
31def crop_scale_3d(motion, scale_range=[1, 1]):
32 ''&#x27;

Callers 6

convert_insta.pyFile · 0.90
read_inputFunction · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90
__init__Method · 0.90
__getitem__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected