def test_denormalize_keypoints(self): profile = keypoint_profiles.KeypointProfile2D( name='Dummy', keypoint_names=[('A', keypoint_profiles.LeftRightType.UNKNOWN), ('B', keypoint_profiles.LeftRightType.UNKNOWN), ('C', keypoint_profiles.LeftRightType.UNKNOWN)], offset_keypoint_names=['A', 'B'], scale_keypoint_name_pairs=[(['A', 'B'], ['B']), (['A'], ['B', 'C'])], segment_name_pairs=[], scale_distance_reduction_fn=tf.math.reduce_sum, scale_unit=1.0) sqrt_2 = 1.414213562 normalized_points = tf.constant([ [[ [-0.25 / sqrt_2, -0.25 / sqrt_2], [0.25 / sqrt_2, 0.25 / sqrt_2], [0.75 / sqrt_2, 0.75 / sqrt_2], ]], [[ [-0.25 / sqrt_2, -0.25 / sqrt_2], [0.25 / sqrt_2, 0.25 / sqrt_2], [0.75 / sqrt_2, 0.75 / sqrt_2], ]], ]) offset_points = [[[[1.0, 2.0]]], [[[11.0, 12.0]]]] scale_distances = [[[[4.0 * sqrt_2]]], [[[4.0 * sqrt_2]]]] denormalized_points = profile.denormalize(normalized_points, offset_points, scale_distances) self.assertAllClose(denormalized_points, [[[[0.0, 1.0], [2.0, 3.0], [4.0, 5.0]]], [[[10.0, 11.0], [12.0, 13.0], [14.0, 15.0]]]])
def test_create_model_keypoints_2d_input(self): keypoint_profile_2d = keypoint_profiles.KeypointProfile2D( name='Dummy', keypoint_names=[('A', keypoint_profiles.LeftRightType.UNKNOWN), ('B', keypoint_profiles.LeftRightType.UNKNOWN), ('C', keypoint_profiles.LeftRightType.UNKNOWN)], offset_keypoint_names=['A', 'B'], scale_keypoint_name_pairs=[(['A', 'B'], ['B']), (['A'], ['B', 'C'])], segment_name_pairs=[], scale_distance_reduction_fn=tf.math.reduce_sum, scale_unit=1.0) # Shape = [2, 3, 2]. keypoints_2d = tf.constant([[[0.0, 1.0], [2.0, 3.0], [4.0, 5.0]], [[10.0, 11.0], [12.0, 13.0], [14.0, 15.0]]]) keypoint_masks_2d = tf.ones([2, 3], dtype=tf.float32) # Shape = [2, 6]. features, side_outputs = input_generator.create_model_input( keypoints_2d, keypoint_masks_2d, keypoints_3d=None, model_input_keypoint_type=common. MODEL_INPUT_KEYPOINT_TYPE_2D_INPUT, normalize_keypoints_2d=True, keypoint_profile_2d=keypoint_profile_2d) sqrt_2 = 1.414213562 self.assertAllClose(features, [[ -0.25 / sqrt_2, -0.25 / sqrt_2, 0.25 / sqrt_2, 0.25 / sqrt_2, 0.75 / sqrt_2, 0.75 / sqrt_2 ], [ -0.25 / sqrt_2, -0.25 / sqrt_2, 0.25 / sqrt_2, 0.25 / sqrt_2, 0.75 / sqrt_2, 0.75 / sqrt_2 ]]) self.assertCountEqual(side_outputs.keys(), [ 'preprocessed_keypoints_2d', 'preprocessed_keypoint_masks_2d', 'offset_points_2d', 'scale_distances_2d' ]) self.assertAllClose( side_outputs['preprocessed_keypoints_2d'], [[[-0.25 / sqrt_2, -0.25 / sqrt_2], [0.25 / sqrt_2, 0.25 / sqrt_2], [0.75 / sqrt_2, 0.75 / sqrt_2]], [[-0.25 / sqrt_2, -0.25 / sqrt_2], [0.25 / sqrt_2, 0.25 / sqrt_2], [0.75 / sqrt_2, 0.75 / sqrt_2]]]) self.assertAllClose(side_outputs['preprocessed_keypoint_masks_2d'], [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]) self.assertAllClose(side_outputs['offset_points_2d'], [[[1.0, 2.0]], [[11.0, 12.0]]]) self.assertAllClose(side_outputs['scale_distances_2d'], [[[4.0 * sqrt_2]], [[4.0 * sqrt_2]]])