有人可以给一些例子吗? 官方文档中没有指南。 我想知道标签和预测的类型是什么? 谢谢。
有人可以给一些例子吗? 官方文档中没有指南。 我想知道标签和预测的类型是什么? 谢谢。
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)