code: def test_normalize_bounding_boxes(self):
      def _assert_single_image_expected(inputs):
          # --> images None
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  inputs, shapes=None
              )
  
          # --> too many images
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  inputs, shapes=np.zeros((2, 1, 1, 3), dtype=np.uint8)
              )
  
          # --> too many images
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  inputs,
                  shapes=[
                      np.zeros((1, 1, 3), dtype=np.uint8),
                      np.zeros((1, 1, 3), dtype=np.uint8),
                  ],
              )
  
      # ----
      # None
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(None)
      assert bbs_norm is None
  
      # ----
      # array
      # ----
      for dt in [
          np.dtype("float32"),
          np.dtype("int16"),
          np.dtype("uint16"),
      ]:
          bbs_norm = normalization.normalize_bounding_boxes(
              np.zeros((1, 1, 4), dtype=dt) + 1,
              shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
          )
          assert isinstance(bbs_norm, list)
          assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
          assert len(bbs_norm[0].bounding_boxes) == 1
          assert np.allclose(bbs_norm[0].to_xyxy_array(), 1)
  
          bbs_norm = normalization.normalize_bounding_boxes(
              np.zeros((1, 5, 4), dtype=dt) + 1,
              shapes=np.zeros((1, 1, 1, 3), dtype=np.uint8),
          )
          assert isinstance(bbs_norm, list)
          assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
          assert len(bbs_norm[0].bounding_boxes) == 5
          assert np.allclose(bbs_norm[0].to_xyxy_array(), 1)
  
          # --> bounding boxes for too many images
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  np.zeros((2, 1, 4), dtype=dt) + 1,
                  shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
              )
  
          # --> too few bounding boxes
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  np.zeros((1, 1, 4), dtype=dt) + 1,
                  shapes=np.zeros((2, 1, 1, 3), dtype=np.uint8),
              )
  
          # --> wrong keypoints shape
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  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, 4), dtype=dt) + 1
          )
  
      # ----
      # (x1,y1,x2,y2)
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          (1, 2, 3, 4), shapes=[np.zeros((1, 1, 3), dtype=np.uint8)]
      )
      assert isinstance(bbs_norm, list)
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 1
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
  
      _assert_single_image_expected((1, 2, 3, 4))
  
      # ----
      # single BoundingBox instance
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          ia.BoundingBox(x1=1, y1=2, x2=3, y2=4),
          shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
      )
      assert isinstance(bbs_norm, list)
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 1
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
  
      _assert_single_image_expected(
          ia.BoundingBox(x1=1, y1=2, x2=3, y2=4)
      )
  
      # ----
      # single BoundingBoxesOnImage instance
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          ia.BoundingBoxesOnImage(
              [ia.BoundingBox(x1=1, y1=2, x2=3, y2=4)], shape=(1, 1, 3)
          ),
          shapes=None,
      )
      assert isinstance(bbs_norm, list)
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 1
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
  
      # ----
      # empty iterable
      # ----
      bbs_norm = normalization.normalize_bounding_boxes([], shapes=None)
      assert bbs_norm is None
  
      # ----
      # iterable of array
      # ----
      for dt in [
          np.dtype("float32"),
          np.dtype("int16"),
          np.dtype("uint16"),
      ]:
          bbs_norm = normalization.normalize_bounding_boxes(
              [np.zeros((1, 4), dtype=dt) + 1],
              shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
          )
          assert isinstance(bbs_norm, list)
          assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
          assert len(bbs_norm[0].bounding_boxes) == 1
          assert np.allclose(bbs_norm[0].to_xyxy_array(), 1)
  
          bbs_norm = normalization.normalize_bounding_boxes(
              [np.zeros((5, 4), dtype=dt) + 1],
              shapes=np.zeros((1, 1, 1, 3), dtype=np.uint8),
          )
          assert isinstance(bbs_norm, list)
          assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
          assert len(bbs_norm[0].bounding_boxes) == 5
          assert np.allclose(bbs_norm[0].to_xyxy_array(), 1)
  
          # --> bounding boxes for too many images
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  [
                      np.zeros((1, 4), dtype=dt) + 1,
                      np.zeros((1, 4), dtype=dt) + 1,
                  ],
                  shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
              )
  
          # --> too few bounding boxes
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  [np.zeros((1, 4), dtype=dt) + 1],
                  shapes=np.zeros((2, 1, 1, 3), dtype=np.uint8),
              )
  
          # --> images None
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  [np.zeros((1, 4), dtype=dt) + 1], shapes=None
              )
  
          # --> wrong shape
          with self.assertRaises(ValueError):
              _bbs_norm = normalization.normalize_bounding_boxes(
                  [np.zeros((1, 100), dtype=dt) + 1],
                  shapes=np.zeros((1, 1, 1, 3), dtype=np.uint8),
              )
  
      # ----
      # iterable of (x1,y1,x2,y2)
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          [(1, 2, 3, 4), (5, 6, 7, 8)],
          shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
      )
      assert isinstance(bbs_norm, list)
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 2
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
      assert bbs_norm[0].bounding_boxes[1].x1 == 5
      assert bbs_norm[0].bounding_boxes[1].y1 == 6
      assert bbs_norm[0].bounding_boxes[1].x2 == 7
      assert bbs_norm[0].bounding_boxes[1].y2 == 8
  
      # may only be used for single images
      with self.assertRaises(ValueError):
          _bbs_norm = normalization.normalize_bounding_boxes(
              [(1, 2, 3, 4)],
              shapes=[
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
              ],
          )
  
      # ----
      # iterable of BoundingBox
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          [
              ia.BoundingBox(x1=1, y1=2, x2=3, y2=4),
              ia.BoundingBox(x1=5, y1=6, x2=7, y2=8),
          ],
          shapes=[np.zeros((1, 1, 3), dtype=np.uint8)],
      )
      assert isinstance(bbs_norm, list)
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 2
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
      assert bbs_norm[0].bounding_boxes[1].x1 == 5
      assert bbs_norm[0].bounding_boxes[1].y1 == 6
      assert bbs_norm[0].bounding_boxes[1].x2 == 7
      assert bbs_norm[0].bounding_boxes[1].y2 == 8
  
      # may only be used for single images
      with self.assertRaises(ValueError):
          _bbs_norm = normalization.normalize_bounding_boxes(
              [ia.BoundingBox(x1=1, y1=2, x2=3, y2=4)],
              shapes=[
                  np.zeros((1, 1, 3), dtype=np.uint8),
                  np.zeros((1, 1, 3), dtype=np.uint8),
              ],
          )
  
      # ----
      # iterable of BoundingBoxesOnImage
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          [
              ia.BoundingBoxesOnImage(
                  [ia.BoundingBox(x1=1, y1=2, x2=3, y2=4)],
                  shape=(1, 1, 3),
              ),
              ia.BoundingBoxesOnImage(
                  [ia.BoundingBox(x1=5, y1=6, x2=7, y2=8)],
                  shape=(1, 1, 3),
              ),
          ],
          shapes=None,
      )
      assert isinstance(bbs_norm, list)
  
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 1
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
  
      assert isinstance(bbs_norm[1], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[1].bounding_boxes) == 1
      assert bbs_norm[1].bounding_boxes[0].x1 == 5
      assert bbs_norm[1].bounding_boxes[0].y1 == 6
      assert bbs_norm[1].bounding_boxes[0].x2 == 7
      assert bbs_norm[1].bounding_boxes[0].y2 == 8
  
      # ----
      # iterable of empty interables
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          [[]], shapes=[np.zeros((1, 1, 3), dtype=np.uint8)]
      )
      assert bbs_norm is None
  
      # ----
      # iterable of iterable of (x1,y1,x2,y2)
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          [[(1, 2, 3, 4)], [(5, 6, 7, 8), (9, 10, 11, 12)]],
          shapes=[
              np.zeros((1, 1, 3), dtype=np.uint8),
              np.zeros((1, 1, 3), dtype=np.uint8),
          ],
      )
      assert isinstance(bbs_norm, list)
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 1
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
  
      assert len(bbs_norm[1].bounding_boxes) == 2
      assert bbs_norm[1].bounding_boxes[0].x1 == 5
      assert bbs_norm[1].bounding_boxes[0].y1 == 6
      assert bbs_norm[1].bounding_boxes[0].x2 == 7
      assert bbs_norm[1].bounding_boxes[0].y2 == 8
  
      assert bbs_norm[1].bounding_boxes[1].x1 == 9
      assert bbs_norm[1].bounding_boxes[1].y1 == 10
      assert bbs_norm[1].bounding_boxes[1].x2 == 11
      assert bbs_norm[1].bounding_boxes[1].y2 == 12
  
      # --> images None
      with self.assertRaises(ValueError):
          _bbs_norm = normalization.normalize_bounding_boxes(
              [
                  [(1, 2, 3, 4), (3, 4, 5, 6)],
                  [(5, 6, 7, 8), (7, 8, 9, 10)],
              ],
              shapes=None,
          )
  
      # --> different number of images
      with self.assertRaises(ValueError):
          _bbs_norm = normalization.normalize_bounding_boxes(
              [[(1, 2, 3, 4)], [(5, 6, 7, 8)]],
              [
                  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
      # ----
      bbs_norm = normalization.normalize_bounding_boxes(
          [
              [
                  ia.BoundingBox(x1=1, y1=2, x2=3, y2=4),
                  ia.BoundingBox(x1=5, y1=6, x2=7, y2=8),
              ],
              [
                  ia.BoundingBox(x1=9, y1=10, x2=11, y2=12),
                  ia.BoundingBox(x1=13, y1=14, x2=15, y2=16),
              ],
          ],
          shapes=[
              np.zeros((1, 1, 3), dtype=np.uint8),
              np.zeros((1, 1, 3), dtype=np.uint8),
          ],
      )
      assert isinstance(bbs_norm, list)
      assert isinstance(bbs_norm[0], ia.BoundingBoxesOnImage)
      assert len(bbs_norm[0].bounding_boxes) == 2
      assert bbs_norm[0].bounding_boxes[0].x1 == 1
      assert bbs_norm[0].bounding_boxes[0].y1 == 2
      assert bbs_norm[0].bounding_boxes[0].x2 == 3
      assert bbs_norm[0].bounding_boxes[0].y2 == 4
      assert bbs_norm[0].bounding_boxes[1].x1 == 5
      assert bbs_norm[0].bounding_boxes[1].y1 == 6
      assert bbs_norm[0].bounding_boxes[1].x2 == 7
      assert bbs_norm[0].bounding_boxes[1].y2 == 8
  
      assert len(bbs_norm[1].bounding_boxes) == 2
      assert bbs_norm[1].bounding_boxes[0].x1 == 9
      assert bbs_norm[1].bounding_boxes[0].y1 == 10
      assert bbs_norm[1].bounding_boxes[0].x2 == 11
      assert bbs_norm[1].bounding_boxes[0].y2 == 12
      assert bbs_norm[1].bounding_boxes[1].x1 == 13
      assert bbs_norm[1].bounding_boxes[1].y1 == 14
      assert bbs_norm[1].bounding_boxes[1].x2 == 15
      assert bbs_norm[1].bounding_boxes[1].y2 == 16
  
      # --> images None
      with self.assertRaises(ValueError):
          _bbs_norm = normalization.normalize_bounding_boxes(
              [
                  [
                      ia.BoundingBox(x1=1, y1=2, x2=3, y2=4),
                      ia.BoundingBox(x1=5, y1=6, x2=7, y2=8),
                  ],
                  [
                      ia.BoundingBox(x1=9, y1=10, x2=11, y2=12),
                      ia.BoundingBox(x1=13, y1=14, x2=15, y2=16),
                  ],
              ],
              shapes=None,
          )
  
      # --> different number of images
      with self.assertRaises(ValueError):
          _bbs_norm = normalization.normalize_bounding_boxes(
              [
                  [
                      ia.BoundingBox(x1=1, y1=2, x2=3, y2=4),
                      ia.BoundingBox(x1=5, y1=6, x2=7, y2=8),
                  ],
                  [
                      ia.BoundingBox(x1=9, y1=10, x2=11, y2=12),
                      ia.BoundingBox(x1=13, y1=14, x2=15, y2=16),
                  ],
              ],
              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 13 for calling the TestNormalization obj's underlying member method code with example usage: obj.test_normalize_bounding_boxes() without return types