class_docstr: loss util unittest
docstr: test ctc_data_transform 
docstr_tok: ["test","ctc_data_transform"]
code: def test_ctc_data_transform(self):
      """test ctc_data_transform"""
      with self.cached_session():
          """
          in this test case, the shape of inputs: (B,T,D) = (1, 3, 6)
                             the shape of labels: (B,T) = (1,3)
          """
          inputs = np.asarray(
              [
                  [
                      [
                          0.633766,
                          0.221185,
                          0.0917319,
                          0.0129757,
                          0.0142857,
                          0.0260553,
                      ],
                      [
                          0.111121,
                          0.588392,
                          0.278779,
                          0.0055756,
                          0.00569609,
                          0.010436,
                      ],
                      [
                          0.0357786,
                          0.633813,
                          0.321418,
                          0.00249248,
                          0.00272882,
                          0.0037688,
                      ],
                  ]
              ],
              dtype=np.float32,
          )
          labels = np.asarray([[1, 2, 3]], dtype=np.int64)
  
          blank_index = 0
          (
              labels_after_transform,
              inputs_after_transform,
          ) = loss_utils.ctc_data_transform(labels, inputs, blank_index)
          labels_after_transform = tf.sparse_tensor_to_dense(
              labels_after_transform
          )
          new_labels = [[0, 1, 2]]
          new_inputs = [
              [
                  [
                      0.221185,
                      0.0917319,
                      0.0129757,
                      0.0142857,
                      0.0260553,
                      0.633766,
                  ],
                  [
                      0.588392,
                      0.278779,
                      0.0055756,
                      0.00569609,
                      0.010436,
                      0.111121,
                  ],
                  [
                      0.633813,
                      0.321418,
                      0.00249248,
                      0.00272882,
                      0.0037688,
                      0.0357786,
                  ],
              ]
          ]
          self.assertAllEqual(labels_after_transform, new_labels)
          self.assertAllClose(inputs_after_transform, new_inputs)
  
          blank_index = 2
          (
              labels_after_transform,
              inputs_after_transform,
          ) = loss_utils.ctc_data_transform(labels, inputs, blank_index)
          labels_after_transform = tf.sparse_tensor_to_dense(
              labels_after_transform
          )
          new_labels = [[1, 5, 2]]
          new_inputs = [
              [
                  [
                      0.633766,
                      0.221185,
                      0.0129757,
                      0.0142857,
                      0.0260553,
                      0.0917319,
                  ],
                  [
                      0.111121,
                      0.588392,
                      0.0055756,
                      0.00569609,
                      0.010436,
                      0.278779,
                  ],
                  [
                      0.0357786,
                      0.633813,
                      0.00249248,
                      0.00272882,
                      0.0037688,
                      0.321418,
                  ],
              ]
          ]
          self.assertAllEqual(labels_after_transform, new_labels)
          self.assertAllClose(inputs_after_transform, new_inputs)
  
          blank_index = 5
          (
              labels_after_transform,
              inputs_after_transform,
          ) = loss_utils.ctc_data_transform(labels, inputs, blank_index)
          labels_after_transform = tf.sparse_tensor_to_dense(
              labels_after_transform
          )
          new_labels = [[1, 2, 3]]
          new_inputs = [
              [
                  [
                      0.633766,
                      0.221185,
                      0.0917319,
                      0.0129757,
                      0.0142857,
                      0.0260553,
                  ],
                  [
                      0.111121,
                      0.588392,
                      0.278779,
                      0.0055756,
                      0.00569609,
                      0.010436,
                  ],
                  [
                      0.0357786,
                      0.633813,
                      0.321418,
                      0.00249248,
                      0.00272882,
                      0.0037688,
                  ],
              ]
          ]
          self.assertAllEqual(labels_after_transform, new_labels)
          self.assertAllClose(inputs_after_transform, new_inputs)
  
          with self.assertRaises(ValueError) as valueErr:
              blank_index = -1
              (
                  labels_after_transform,
                  inputs_after_transform,
              ) = loss_utils.ctc_data_transform(
                  labels, inputs, blank_index
              )
          the_exception = valueErr.exception
          self.assertEqual(
              str(the_exception),
              "blank_index must be greater than or equal to zero",
          )
  
          with self.assertRaises(ValueError) as valueErr:
              blank_index = 10
              (
                  labels_after_transform,
                  inputs_after_transform,
              ) = loss_utils.ctc_data_transform(
                  labels, inputs, blank_index
              )
          the_exception = valueErr.exception
          self.assertEqual(
              str(the_exception),
              "blank_index must be less than or equal to num_class - 1",
          )
  
file_path: delta/delta/utils/loss/loss_utils_test.py
imports: import numpy
  import delta.compat
  from absl import logging
  from delta.utils.loss import loss_utils
label_desc: Use image node_id 5 for calling the LossUtilTest obj's underlying member method code with example usage: obj.test_ctc_data_transform() without return types