Skip to content

Commit

Permalink
fix: use tf.nn.softmax() only with cross_entropy loss
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieleangeletti committed May 6, 2016
1 parent 1bcc1ef commit 20d1b59
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def _create_cost_function_node(self, loss_func, model_output, ref_input, regterm

with tf.name_scope("cost"):
if loss_func == 'cross_entropy':
model_output = tf.nn.softmax(model_output)
cost = - tf.reduce_mean(ref_input * tf.log(tf.clip_by_value(model_output, 1e-10, float('inf'))) +
(1 - ref_input) * tf.log(tf.clip_by_value(1 - model_output, 1e-10, float('inf'))))
_ = tf.scalar_summary("cross_entropy", cost)
Expand Down
2 changes: 1 addition & 1 deletion models/autoencoder_models/stacked_denoising_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _create_softmax_layer(self, last_layer, n_classes):
self.softmax_b = tf.Variable(tf.constant(0.1, shape=[n_classes]), name='sm-biases')

with tf.name_scope("softmax_layer"):
self.softmax_out = tf.nn.softmax(tf.matmul(last_layer, self.softmax_W) + self.softmax_b)
self.softmax_out = tf.matmul(last_layer, self.softmax_W) + self.softmax_b
self.layer_nodes.append(self.softmax_out)

def _create_test_node(self):
Expand Down
2 changes: 1 addition & 1 deletion models/rbm_models/dbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _create_softmax_layer(self, next_train, n_classes):
self.softmax_b = tf.Variable(tf.constant(0.1, shape=[n_classes]), name='softmax-biases')

with tf.name_scope("softmax_layer"):
self.y = tf.nn.softmax(tf.matmul(next_train, self.softmax_W) + self.softmax_b)
self.y = tf.matmul(next_train, self.softmax_W) + self.softmax_b

def _create_test_node(self):

Expand Down

0 comments on commit 20d1b59

Please sign in to comment.