waleedka / traffic-signs-tensorflow

Traffic Signs Detection and Recognition with Tensorflow
291 stars 141 forks source link

Tip to simplify network by removing softmax #1

Closed wichersn closed 7 years ago

wichersn commented 7 years ago

I attended your Traffic Sign Recognition with TensorFlow talk yesterday, thanks for the presentation.

I have a small tip for you to simplify the neural network in your example further. Currently, you're passing the output from the softmax into tf.argmax. The softmax part is unnecessary though, since the maximum value stays the same no matter if softmax is used or not. So you can remove the softmax line and use predicted_labels = tf.argmax(logits, 1). This model will perform the same as the original. Also you can run the following example to see that the softmax doesn't effect the result of argmax:

example_data = [4.3, 6.6, 8.3, 2.7, 5.5, 4.8, 9.5, 5.6, 4.3]
print("softmax", tf.nn.softmax(example_data).eval(session=tf.Session()))
print("argmax", tf.argmax(example_data, 0).eval(session=tf.Session()))
print("softmax then argmax", tf.argmax(tf.nn.softmax(example_data), 0).eval(session=tf.Session()))

Note that even with this change, your model still uses softmax in the sparse_softmax_cross_entropy_with_logits function. See the documentation for it here.

waleedka commented 7 years ago

Good point! I use softmax often to display results in an interpretable way so I used it here as well out of habit. But, indeed, I'm not even printing the values after the softmax here so it's not necessary. I'll make the update.