Skip to content

Commit 8af336b

Browse files
committed
cosine_distance and softmax_cross_entropy_with_logits_v2 changed with tf 1.5.
1 parent 473aedc commit 8af336b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/DataDrivenSampler/models/neuralnetwork.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import numpy as np
33
import tensorflow as tf
44

5+
from distutils.version import LooseVersion
6+
57
from DataDrivenSampler.models.basetype import dds_basetype
68
from DataDrivenSampler.samplers.BAOAB import BAOABSampler
79
from DataDrivenSampler.samplers.GLAFirstOrderMomentumSampler import GLAFirstOrderMomentumSampler
@@ -312,12 +314,17 @@ def add_losses(self, y, y_):
312314
:param y_: true labels
313315
"""
314316
with tf.name_scope('loss'):
315-
softmax_cross_entropy = tf.reduce_mean(
316-
tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))
317317
sigmoid_cross_entropy = tf.reduce_mean(
318318
tf.nn.sigmoid_cross_entropy_with_logits(labels=y_, logits=y))
319319
absolute_difference = tf.losses.absolute_difference(labels=y_, predictions=y)
320-
cosine_distance = tf.losses.cosine_distance(labels=y_, predictions=y, dim=1)
320+
if LooseVersion(tf.__version__) < LooseVersion("1.5.0"):
321+
cosine_distance = tf.losses.cosine_distance(labels=y_, predictions=y, dim=1)
322+
softmax_cross_entropy = tf.reduce_mean(
323+
tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))
324+
else:
325+
cosine_distance = tf.losses.cosine_distance(labels=y_, predictions=y, axis=1)
326+
softmax_cross_entropy = tf.reduce_mean(
327+
tf.nn.softmax_cross_entropy_with_logits_v2(labels=y_, logits=y))
321328
hinge_loss = tf.losses.hinge_loss(labels=y_, logits=y)
322329
log_loss = tf.losses.log_loss(labels=y_, predictions=y)
323330
mean_squared = tf.losses.mean_squared_error(labels=y_, predictions=y)

0 commit comments

Comments
 (0)