code: def test_normalize_keypoints(self):
      def _assert_single_image_expected(inputs):
          # --> images None
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  inputs, None
              )
  
          # --> too many images
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  inputs, shapes=np.zeros((2, 1, 1, 3), dtype=np.uint8)
              )
  
          # --> too many images
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  inputs,
                  shapes=[
                      np.zeros((1, 1, 3), dtype=np.uint8),
                      np.zeros((1, 1, 3), dtype=np.uint8),
                  ],
              )
  
      # ----
      # None
      # ----
      keypoints_norm = normalization.normalize_keypoints(None)
      assert keypoints_norm is None
  
      # ----
      # array
      # ----
      for dt in [
          np.dtype("float32"),
          np.dtype("int16"),
          np.dtype("uint16"),
      ]:
          keypoints_norm = normalization.normalize_keypoints(
              np.zeros((1, 1, 2), dtype=dt) + 1,
              shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
          )
          assert isinstance(keypoints_norm, list)
          assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
          assert len(keypoints_norm[0].keypoints) == 1
          assert np.allclose(keypoints_norm[0].to_xy_array(), 1)
  
          keypoints_norm = normalization.normalize_keypoints(
              np.zeros((1, 5, 2), dtype=dt) + 1,
              shapes=np.zeros((1, 1, 1, 3), dtype=np.uint8),
          )
          assert isinstance(keypoints_norm, list)
          assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
          assert len(keypoints_norm[0].keypoints) == 5
          assert np.allclose(keypoints_norm[0].to_xy_array(), 1)
  
          # --> keypoints for too many images
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  np.zeros((2, 1, 2), dtype=dt) + 1,
                  shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
              )
  
          # --> too few keypoints
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  np.zeros((1, 1, 2), dtype=dt) + 1,
                  shapes=np.zeros((2, 1, 1, 3), dtype=np.uint8),
              )
  
          # --> wrong keypoints shape
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  np.zeros((1, 1, 100), dtype=dt) + 1,
                  shapes=np.zeros((1, 1, 1, 3), dtype=np.uint8),
              )
  
          _assert_single_image_expected(
              np.zeros((1, 1, 2), dtype=dt) + 1
          )
  
      # ----
      # (x,y)
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          (1, 2), shapes=[np.zeros((1, 1, 3), dtype=np.uint8)]
      )
      assert isinstance(keypoints_norm, list)
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 1
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
  
      _assert_single_image_expected((1, 2))
  
      # ----
      # single Keypoint instance
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          ia.Keypoint(x=1, y=2),
          shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
      )
      assert isinstance(keypoints_norm, list)
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 1
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
  
      _assert_single_image_expected(ia.Keypoint(x=1, y=2))
  
      # ----
      # single KeypointsOnImage instance
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          ia.KeypointsOnImage([ia.Keypoint(x=1, y=2)], shape=(1, 1, 3)),
          shapes=None,
      )
      assert isinstance(keypoints_norm, list)
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 1
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
  
      # ----
      # empty iterable
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          [], shapes=None
      )
      assert keypoints_norm is None
  
      # ----
      # iterable of array
      # ----
      for dt in [
          np.dtype("float32"),
          np.dtype("int16"),
          np.dtype("uint16"),
      ]:
          keypoints_norm = normalization.normalize_keypoints(
              [np.zeros((1, 2), dtype=dt) + 1],
              shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
          )
          assert isinstance(keypoints_norm, list)
          assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
          assert len(keypoints_norm[0].keypoints) == 1
          assert np.allclose(keypoints_norm[0].to_xy_array(), 1)
  
          keypoints_norm = normalization.normalize_keypoints(
              [np.zeros((5, 2), dtype=dt) + 1],
              shapes=np.zeros((1, 1, 1, 3), dtype=np.uint8),
          )
          assert isinstance(keypoints_norm, list)
          assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
          assert len(keypoints_norm[0].keypoints) == 5
          assert np.allclose(keypoints_norm[0].to_xy_array(), 1)
  
          # --> keypoints for too many images
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  [
                      np.zeros((1, 2), dtype=dt) + 1,
                      np.zeros((1, 2), dtype=dt) + 1,
                  ],
                  shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
              )
  
          # --> too few keypoints
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  [np.zeros((1, 2), dtype=dt) + 1],
                  shapes=np.zeros((2, 1, 1, 3), dtype=np.uint8),
              )
  
          # --> images None
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  [np.zeros((1, 2), dtype=dt) + 1], shapes=None
              )
  
          # --> wrong shape
          with self.assertRaises(ValueError):
              _keypoints_norm = normalization.normalize_keypoints(
                  [np.zeros((1, 100), dtype=dt) + 1],
                  shapes=np.zeros((1, 1, 1, 3), dtype=np.uint8),
              )
  
      # ----
      # iterable of (x,y)
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          [(1, 2), (3, 4)], shapes=[np.zeros((1, 1, 3), dtype=np.uint8)]
      )
      assert isinstance(keypoints_norm, list)
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 2
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
      assert keypoints_norm[0].keypoints[1].x == 3
      assert keypoints_norm[0].keypoints[1].y == 4
  
      # may only be used for single images
      with self.assertRaises(ValueError):
          _keypoints_norm = normalization.normalize_keypoints(
              [(1, 2)],
              shapes=[
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
              ],
          )
  
      # ----
      # iterable of Keypoint
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)],
          shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
      )
      assert isinstance(keypoints_norm, list)
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 2
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
      assert keypoints_norm[0].keypoints[1].x == 3
      assert keypoints_norm[0].keypoints[1].y == 4
  
      # may only be used for single images
      with self.assertRaises(ValueError):
          _keypoints_norm = normalization.normalize_keypoints(
              [ia.Keypoint(x=1, y=2)],
              shapes=[
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
              ],
          )
  
      # ----
      # iterable of KeypointsOnImage
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          [
              ia.KeypointsOnImage(
                  [ia.Keypoint(x=1, y=2)], shape=(1, 1, 3)
              ),
              ia.KeypointsOnImage(
                  [ia.Keypoint(x=3, y=4)], shape=(1, 1, 3)
              ),
          ],
          shapes=None,
      )
      assert isinstance(keypoints_norm, list)
  
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 1
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
  
      assert isinstance(keypoints_norm[1], ia.KeypointsOnImage)
      assert len(keypoints_norm[1].keypoints) == 1
      assert keypoints_norm[1].keypoints[0].x == 3
      assert keypoints_norm[1].keypoints[0].y == 4
  
      # ----
      # iterable of empty interables
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          [[]], shapes=[np.zeros((1, 1, 3), dtype=np.uint8)]
      )
      assert keypoints_norm is None
  
      # ----
      # iterable of iterable of (x,y)
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          [[(1, 2), (3, 4)], [(5, 6), (7, 8)]],
          shapes=[
              np.zeros((1, 1, 3), dtype=np.uint8),
              np.zeros((1, 1, 3), dtype=np.uint8),
          ],
      )
      assert isinstance(keypoints_norm, list)
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 2
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
      assert keypoints_norm[0].keypoints[1].x == 3
      assert keypoints_norm[0].keypoints[1].y == 4
  
      assert len(keypoints_norm[1].keypoints) == 2
      assert keypoints_norm[1].keypoints[0].x == 5
      assert keypoints_norm[1].keypoints[0].y == 6
      assert keypoints_norm[1].keypoints[1].x == 7
      assert keypoints_norm[1].keypoints[1].y == 8
  
      # --> images None
      with self.assertRaises(ValueError):
          _keypoints_norm = normalization.normalize_keypoints(
              [[(1, 2), (3, 4)], [(5, 6), (7, 8)]], shapes=None
          )
  
      # --> different number of images
      with self.assertRaises(ValueError):
          _keypoints_norm = normalization.normalize_keypoints(
              [[(1, 2), (3, 4)], [(5, 6), (7, 8)]],
              shapes=[
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
              ],
          )
  
      # ----
      # iterable of iterable of Keypoint
      # ----
      keypoints_norm = normalization.normalize_keypoints(
          [
              [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)],
              [ia.Keypoint(x=5, y=6), ia.Keypoint(x=7, y=8)],
          ],
          shapes=[
              np.zeros((1, 1, 3), dtype=np.uint8),
              np.zeros((1, 1, 3), dtype=np.uint8),
          ],
      )
      assert isinstance(keypoints_norm, list)
      assert isinstance(keypoints_norm[0], ia.KeypointsOnImage)
      assert len(keypoints_norm[0].keypoints) == 2
      assert keypoints_norm[0].keypoints[0].x == 1
      assert keypoints_norm[0].keypoints[0].y == 2
      assert keypoints_norm[0].keypoints[1].x == 3
      assert keypoints_norm[0].keypoints[1].y == 4
  
      assert len(keypoints_norm[1].keypoints) == 2
      assert keypoints_norm[1].keypoints[0].x == 5
      assert keypoints_norm[1].keypoints[0].y == 6
      assert keypoints_norm[1].keypoints[1].x == 7
      assert keypoints_norm[1].keypoints[1].y == 8
  
      # --> images None
      with self.assertRaises(ValueError):
          _keypoints_norm = normalization.normalize_keypoints(
              [
                  [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)],
                  [ia.Keypoint(x=5, y=6), ia.Keypoint(x=7, y=8)],
              ],
              shapes=None,
          )
  
      # --> different number of images
      with self.assertRaises(ValueError):
          _keypoints_norm = normalization.normalize_keypoints(
              [
                  [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)],
                  [ia.Keypoint(x=5, y=6), ia.Keypoint(x=7, y=8)],
              ],
              shapes=[
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
              ],
          )
  
imports: from __future__ import print_function, division, absolute_import
  import sys
  import numpy
  import six.moves
  import imgaug
  import imgaug.augmentables.normalization
  from imgaug.testutils import reseed
label_desc: Use image node_id 12 for calling the TestNormalization obj's underlying member method code with example usage: obj.test_normalize_keypoints() without return types