File size: 1,151 Bytes
9313a90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np

from fall_detection.features import FEATURE_DIM, normalize_pose_sequence


def random_visible_pose(seed: int = 0) -> np.ndarray:
    rng = np.random.default_rng(seed)
    poses = rng.normal(size=(12, 33, 4)).astype(np.float32)
    poses[:, :, :2] = poses[:, :, :2] * 0.05 + 0.5
    poses[:, :, 3] = 1.0
    return poses


def test_feature_shape_and_finiteness() -> None:
    features = normalize_pose_sequence(random_visible_pose())
    assert features.shape == (12, FEATURE_DIM)
    assert np.isfinite(features).all()


def test_translation_does_not_change_normalized_coordinates() -> None:
    poses = random_visible_pose()
    translated = poses.copy()
    translated[:, :, 0] += 0.20
    translated[:, :, 1] -= 0.15
    original_features = normalize_pose_sequence(poses)
    translated_features = normalize_pose_sequence(translated)
    # Normalized xyz and static geometry are translation invariant. The last
    # motion features may differ by tiny finite-precision gradients.
    np.testing.assert_allclose(
        original_features[:, : 33 * 4 + 5],
        translated_features[:, : 33 * 4 + 5],
        atol=2e-5,
    )