code: def test_check_and_transform_label_format(self):
      labels_expected = np.array(
          [[0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 1]]
      )
      labels_expected_binary = np.array([[0, 1], [1, 0], [0, 1]])
  
      # test input shape (nb_samples,)
      labels = np.array([3, 1, 4])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=5, return_one_hot=True
      )
      np.testing.assert_array_equal(labels_transformed, labels_expected)
  
      # test input shape (nb_samples, 1)
      labels = np.array([[3], [1], [4]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=5, return_one_hot=True
      )
      np.testing.assert_array_equal(labels_transformed, labels_expected)
  
      # test input shape (nb_samples, 1) - binary
      labels = np.array([[1], [0], [1]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=2, return_one_hot=True
      )
      np.testing.assert_array_equal(
          labels_transformed, labels_expected_binary
      )
  
      # test input shape (nb_samples, 1) - binary
      labels = np.array([[0, 1], [1, 0], [0, 1]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=2, return_one_hot=True
      )
      np.testing.assert_array_equal(
          labels_transformed, labels_expected_binary
      )
  
      # test input shape (nb_samples, nb_classes)
      labels = np.array(
          [[0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 1]]
      )
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=5, return_one_hot=True
      )
      np.testing.assert_array_equal(labels_transformed, labels_expected)
  
      # test input shape (nb_samples, nb_classes) with return_one_hot=False
      labels = np.array(
          [[0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 1]]
      )
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=5, return_one_hot=False
      )
      np.testing.assert_array_equal(
          labels_transformed,
          np.expand_dims(np.argmax(labels_expected, axis=1), axis=1),
      )
  
      # test input shape (nb_samples, 1) - binary
      labels = np.array([[1], [0], [1]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=2, return_one_hot=False
      )
      np.testing.assert_array_equal(
          labels_transformed,
          np.expand_dims(
              np.argmax(labels_expected_binary, axis=1), axis=1
          ),
      )
  
      # with no nb_classes
  
      # test input shape (nb_samples,)
      labels = np.array([3, 1, 4])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=None, return_one_hot=True
      )
      np.testing.assert_array_equal(labels_transformed, labels_expected)
  
      # test input shape (nb_samples, 1)
      labels = np.array([[3], [1], [4]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=None, return_one_hot=True
      )
      np.testing.assert_array_equal(labels_transformed, labels_expected)
  
      # test input shape (nb_samples, 1) - binary
      labels = np.array([[1], [0], [1]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=None, return_one_hot=True
      )
      np.testing.assert_array_equal(
          labels_transformed, labels_expected_binary
      )
  
      # test input shape (nb_samples, 1) - binary
      labels = np.array([[0, 1], [1, 0], [0, 1]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=None, return_one_hot=True
      )
      np.testing.assert_array_equal(
          labels_transformed, labels_expected_binary
      )
  
      # test input shape (nb_samples, nb_classes)
      labels = np.array(
          [[0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 1]]
      )
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=None, return_one_hot=True
      )
      np.testing.assert_array_equal(labels_transformed, labels_expected)
  
      # test input shape (nb_samples, nb_classes) with return_one_hot=False
      labels = np.array(
          [[0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 1]]
      )
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=None, return_one_hot=False
      )
      np.testing.assert_array_equal(
          labels_transformed,
          np.expand_dims(np.argmax(labels_expected, axis=1), axis=1),
      )
  
      # test input shape (nb_samples, 1) - binary
      labels = np.array([[1], [0], [1]])
      labels_transformed = check_and_transform_label_format(
          labels, nb_classes=None, return_one_hot=False
      )
      np.testing.assert_array_equal(
          labels_transformed,
          np.expand_dims(
              np.argmax(labels_expected_binary, axis=1), axis=1
          ),
      )
  
      # ValueError for len(labels.shape) > 2
      labels = np.array(
          [[[0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 1]]]
      )
      with self.assertRaises(ValueError):
          check_and_transform_label_format(labels, nb_classes=None)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  import tensorflow
  from art.utils import projection, random_sphere, uniform_sample_from_sphere_or_ball, to_categorical, least_likely_class
  from art.utils import load_dataset, load_iris, load_mnist, load_nursery, load_cifar10
  from art.utils import second_most_likely_class, random_targets, get_label_conf, get_labels_np_array, preprocess
  from art.utils import compute_success_array, compute_success, check_and_transform_label_format
  from art.utils import segment_by_class, performance_diff
  from art.utils import is_probability
  from tests.utils import master_seed
label_desc: Use image node_id 12 for calling the TestUtils obj's underlying member method code with example usage: obj.test_check_and_transform_label_format() without return types