TensorFlow有两种方法来评估图的一部分:Session.run在变量列表和Tensor.eval.这两者有区别吗?
我正在使用EstimatorTensorflow 的 API,遇到以下问题。我想检查 f1 分数而不是准确性,当我在训练后评估时,根本没有问题,当我测试时,它要求标准化值,我已经标准化了。
这是我的网络模型(第一部分省略):
#### architecture omitted #####
predictions = {
"classes": tf.argmax(input=logits, axis=1),
"probabilities": tf.nn.sigmoid_cross_entropy_with_logits(labels=tf.cast(labels, tf.float32), logits=tf.cast(logits, tf.float32), name="sigmoid_tensor")
}
if mode == tf.estimator.ModeKeys.PREDICT:
return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)
loss = tf.losses.sigmoid_cross_entropy(multi_class_labels=labels, logits=logits)
if mode == tf.estimator.ModeKeys.TRAIN:
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
#optimizer = tf.train.MomentumOptimizer(learning_rate=0.01, momentum=0.96)
train_op = optimizer.minimize(
loss=loss,
global_step=tf.train.get_global_step())
logging_hook = tf.train.LoggingTensorHook({"loss" : loss}, every_n_iter=10)
return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op, training_hooks = [logging_hook])
eval_metric_ops = {
"accuracy": tf.metrics.accuracy(
labels=tf.argmax(input=labels, axis=1),
predictions=predictions["classes"]),
"f1 score" : tf.contrib.metrics.f1_score(
labels = tf.argmax(input=labels, …Run Code Online (Sandbox Code Playgroud) 我已经在使用TensorFlow的帮助下实现了Nueral Network模型的分类.但是,我不知道如何通过使用预测分数(准确度)来绘制混淆矩阵.我不是TensorFlow的专家,仍处于学习阶段.在这里,我粘贴了下面的代码,请告诉我如何编写代码以便从以下代码中产生混淆:
# Launch the graph
with tf.Session() as sess:
sess.run(init)
# Set logs writer into folder /tmp/tensorflow_logs
#summary_writer = tf.train.SummaryWriter('/tmp/tensorflow_logs', graph_def=sess.graph_def)
# Training cycle
for epoch in range(training_epochs):
avg_cost = 0.
total_batch = int(X_train.shape[0]/batch_size)
# Loop over total length of batches
for i in range(total_batch):
#picking up random batches from training set of specific size
batch_xs, batch_ys = w2v_utils.nextBatch(X_train, y_train, batch_size)
# Fit training using batch data
sess.run(optimizer, feed_dict={x: batch_xs, y: batch_ys})
# Compute average loss
avg_cost += sess.run(cost, …Run Code Online (Sandbox Code Playgroud)