Skip to content

Bug: Tests can fail in rare cases with random data #155

@cleong110

Description

@cleong110

Related to #146 possibly. Once in a while, tests like this one will fail, because the data used is randomly generated.

def test_pose_tf_posebody_normalize_eager_mode_preserves_shape(self):

Possible solutions:

  1. If we fix Minor bug: pose.normalize can divide by zero, filling data with nan values #146 it can fix this
  2. Adjust the test data generation to ensure 0a and 0b are farther apart.

Example:

=================================== FAILURES ===================================
_ TestPoseTensorflowPoseBody.test_pose_tf_posebody_normalize_distribution_eager_mode_correct_result _

self = <tests.pose_test.TestPoseTensorflowPoseBody testMethod=test_pose_tf_posebody_normalize_distribution_eager_mode_correct_result>

    def test_pose_tf_posebody_normalize_distribution_eager_mode_correct_result(self):
        """
        Tests if the normalization of distribution for Pose object with TensorFlow PoseBody returns expected result.
        """
        pose = _get_random_pose_object_with_tf_posebody(num_keypoints=5, frames_min=2)
    
        tensor_as_numpy = pose.body.data.tensor.numpy()
        mask_as_numpy = pose.body.data.mask.numpy()
        masked_numpy_array = ma.array(tensor_as_numpy, mask=np.logical_not(mask_as_numpy))
    
        axis = (0, 1)
    
        numpy_mean = ma.mean(masked_numpy_array, axis=axis)
        numpy_std = ma.std(masked_numpy_array, axis=axis)
        expected_tensor = (masked_numpy_array - numpy_mean) / numpy_std
        expected_tensor = expected_tensor.filled(0)
    
        pose.normalize_distribution(axis=axis)
    
        actual_tensor_nan_fixed = pose.body.data.fix_nan()
        actual_tensor_zero_filled = actual_tensor_nan_fixed.zero_filled()
        actual_tensor_as_numpy = actual_tensor_zero_filled.numpy()
    
>       self.assertTrue(np.allclose(actual_tensor_as_numpy, expected_tensor),
                        "Normalize distribution did not return the expected result.")
E       AssertionError: False is not true : Normalize distribution did not return the expected result.

tests/pose_test.py:486: AssertionError
=============================== warnings summary ===============================
tests/hand_normalization_test.py::Test3DNormalization::test_hand_normalization
  /home/runner/work/pose/pose/src/python/pose_format/utils/normalization_3d.py:98: RuntimeWarning: invalid value encountered in divide
    normal /= np.linalg.norm(normal, axis=-1, keepdims=True)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/pose_test.py::TestPoseTensorflowPoseBody::test_pose_tf_posebody_normalize_distribution_eager_mode_correct_result - AssertionError: False is not true : Normalize distribution did not return the expected result.
=================== 1 failed, 29 passed, 1 warning in 52.60s ===================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions