任何人都可以提供一些例子吗? 官方文件中没有指南。 我想知道什么类型的标签和预测? 感谢。
答案 0 :(得分:0)
输入是张量,第一个包含对数据点的正确预测,第二个是模型为数据点给出的实际预测。这些张量可以表示单个数据点,如示例或批处理。它们必须具有相同的形状。
实例:
import tensorflow as tf
""" Minimal example """
with tf.Session() as sess:
loss = tf.losses.log_loss(tf.Variable([0., 1., 0.]), tf.Variable([0.1, 0.8, 0.1]))
sess.run(tf.global_variables_initializer())
result = sess.run(loss)
print('Minimal example loss: %f' % result)
tf.reset_default_graph()
""" More realistic example """
with tf.Session() as sess:
# Create placeholders for inputs
X_placeholder = tf.placeholder(tf.float32, [3])
y_placeholder = tf.placeholder(tf.float32, [3])
# Set up the model structure, resulting in a set of predictions
predictions = tf.multiply(X_placeholder, 2.)
# Compute the loss of the calculated predictions
loss = tf.losses.log_loss(y_placeholder, predictions)
# Run the loss tensor with values for the placeholders
result = sess.run(loss, feed_dict={X_placeholder: [0.5, 0.5, 0.5], y_placeholder: [0., 1., 0.]})
print('Realistic example loss: %f' % result)