def test_normalize_points(self): # Shape = [2, 1, 3, 2]. 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]]]] offset_point_indices = [0, 1] scale_distance_point_index_pairs = [([0, 1], [1]), ([0], [1, 2])] normalized_points, offset_points, scale_distances = ( keypoint_utils.normalize_points( points, offset_point_indices=offset_point_indices, scale_distance_point_index_pairs= scale_distance_point_index_pairs, scale_distance_reduction_fn=tf.math.reduce_sum, scale_unit=1.0)) sqrt_2 = 1.414213562 self.assertAllClose(normalized_points, [ [[ [-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(offset_points, [[[[1.0, 2.0]]], [[[11.0, 12.0]]]]) self.assertAllClose(scale_distances, [[[[4.0 * sqrt_2]]], [[[4.0 * sqrt_2]]]])
def normalize(self, keypoints, keypoint_masks=None): """Normalizes keypoints.""" del keypoint_masks return keypoint_utils.normalize_points( keypoints, offset_point_indices=self._offset_keypoint_index, scale_distance_point_index_pairs=self._scale_keypoint_index_pairs, scale_distance_reduction_fn=self._scale_distance_reduction_fn, scale_unit=self._scale_unit)