(labels=None, blank_index=None, num_class=None)
return labels
Ensure that the value of blank_index is in a reasonable range,
      and transform the DenseTensor labels to a SparseTensor
Ensure that the value of blank_index is in a reasonable range,
      and transform the DenseTensor labels to a SparseTensor
Ensure that the value of blank_index is in a reasonable range and transform the DenseTensor labels to a SparseTensor
def transform_preprocess(labels=None, blank_index=None, num_class=None):
  ''' Ensure that the value of blank_index is in a reasonable range,
      and transform the DenseTensor labels to a SparseTensor '''
  if blank_index is None or blank_index < 0:
    raise ValueError('blank_index must be greater than or equal to zero')

  if not num_class is None and blank_index > (num_class - 1):
    raise ValueError('blank_index must be less than or equal to num_class - 1')

  if labels is None:
    return None

  if not isinstance(labels, tf.SparseTensor):
    labels = tf.cast(labels, tf.int32)
    labels_idx = tf.where(tf.not_equal(labels, 0))
    labels_values = tf.gather_nd(labels, labels_idx)
    labels_shape = tf.cast(tf.shape(labels), dtype=tf.int64)
    labels = tf.SparseTensor(
        indices=labels_idx, values=labels_values, dense_shape=labels_shape)

  return labels
def transform_preprocess ( labels = None , blank_index = None , num_class = None ) : if blank_index is None or blank_index < 0 : raise ValueError ( 'blank_index must be greater than or equal to zero' ) if not num_class is None and blank_index > ( num_class - 1 ) : raise ValueError ( 'blank_index must be less than or equal to num_class - 1' ) if labels is None : return None if not isinstance ( labels , tf . SparseTensor ) : labels = tf . cast ( labels , tf . int32 ) labels_idx = tf . where ( tf . not_equal ( labels , 0 ) ) labels_values = tf . gather_nd ( labels , labels_idx ) labels_shape = tf . cast ( tf . shape ( labels ) , dtype = tf . int64 ) labels = tf . SparseTensor ( indices = labels_idx , values = labels_values , dense_shape = labels_shape ) return labels