Skip to content

Commit 93e9971

Browse files
committed
[cost] cross entropy no name under TF0.12
1 parent 778b5b2 commit 93e9971

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tensorlayer/cost.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ def cross_entropy(output, target, name=None):
3232
- About cross-entropy: `wiki <https://en.wikipedia.org/wiki/Cross_entropy>`_.\n
3333
- The code is borrowed from: `here <https://en.wikipedia.org/wiki/Cross_entropy>`_.
3434
"""
35-
assert name is not None, "Please give a unique name to tl.cost.cross_entropy"
36-
37-
try: # TF 1.0
38-
return tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels=target, logits=output, name=name))
39-
except:
35+
try: # old
4036
return tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=output, targets=target))
37+
except: # TF 1.0
38+
assert name is not None, "Please give a unique name to tl.cost.cross_entropy for TF1.0+"
39+
return tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels=target, logits=output, name=name))
4140

4241
def sigmoid_cross_entropy(output, target, name=None):
4342
"""It is a sigmoid cross-entropy operation, see ``tf.nn.sigmoid_cross_entropy_with_logits``.

0 commit comments

Comments
 (0)