Download tests/test_features.py from minhy112/FallKLTN: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/minhy112/FallKLTN/resolve/main/tests/test_features.py
- Command line
-
hf download hf://minhy112/FallKLTN/tests/test_features.py
-
curl -L -o test_features.py https://huggingface.co/minhy112/FallKLTN/resolve/main/tests/test_features.py
1.15 kB
| 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, | |
| ) | |