Search code examples
tensorflowneural-networkloss-function

Output of tf.softmax_cross_entroy_with_logits unnormalized?


I implemented a simple cnn network for image classification (binary classification). I am using tensorflow in Python. I am using tf.softmax_cross_entropy_with logits as a cost function. I feed the cost function with unnormalized logits from the output layer of my model. Should the function output normalized probabilities, or am I wrong?

During training of my model I am printing cost of every single example. If the model correctly predicts the output, the cost equals 0.0, otherwise the cost is very big, unnormalized value). While the function 'softmaxes' input before calculating cross entropy, why the output is unnormalized?


Solution

  • You are mistaking cross-entropy (your loss function) with softmax (the "virtual" output of your net -- see below). Softmax is normalized, but cross-entropy is not -- it can take arbitrarily high values to penalize bad predictions.

    When you use a non-normalized net output in combination with tf.softmax_cross_entropy_with logits, you actually don't observe the softmax output: it is processed within the cost function and remains virtual. To peek at the softmax you can compute it explicitely using tf.nn.softmax on the non-normalized output of your net.