'Add the appropriate loss function.
Args:
logits:  Pre-softmax/logistic fully-connected output shaped to out_dims.
height_in:  Height of logits before going into the softmax layer.
out_dims:   Number of output dimensions, 0, 1 or 2.
out_func:   Output non-linearity. \'s\' or \'c\'=softmax, \'l\'=logistic.
Returns:
loss: That which is to be minimized.
Raises:
ValueError: if logistic is used.'

def _AddLossFunction(self, logits, height_in, out_dims, out_func):

    if (out_func == 'c'):
        ctc_input = tf.transpose(logits, [1, 0, 2])
        widths = self.layers.GetLengths(dim=2, factor=height_in)
        cross_entropy = tf.nn.ctc_loss(ctc_input, self.sparse_labels, widths)
    elif (out_func == 's'):
        if (out_dims == 2):
            self.labels = _PadLabels3d(logits, self.labels)
        elif (out_dims == 1):
            self.labels = _PadLabels2d(shapes.tensor_dim(logits, dim=1), self.labels)
        else:
            self.labels = tf.slice(self.labels, [0, 0], [(-1), 1])
            self.labels = tf.reshape(self.labels, [(-1)])
        cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=self.labels, name='xent')
    else:
        raise ValueError('Logistic    not    yet    supported!')
    return tf.reduce_sum(cross_entropy)
