-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlosses.py
23 lines (21 loc) · 886 Bytes
/
losses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import tensorflow as tf
# def SoftmaxLoss():
# """softmax loss"""
# def softmax_loss(y_true, y_pred):
# # y_true: sparse target
# # y_pred: logist
# y_true = tf.cast(tf.reshape(y_true, [-1]), tf.int32)
# ce = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y_true,
# logits=y_pred)
# return tf.reduce_mean(ce)
# return softmax_loss
def softmax_loss(y_true, y_pred):
# y_true: sparse target
# y_pred: logist
y_true = tf.cast(tf.reshape(y_true, [-1]), tf.int32)
ce = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y_true,
logits=y_pred)
# tf.print("target: ", y_true)
# tf.print("logit: ", y_pred)
# tf.print("softmax_loss: ", tf.reduce_mean(ce))
return tf.reduce_mean(ce)