def batch_dev_step(x_batch, y_batch, writer=None):
"""
Evaluates model on a dev set
"""
batches = data_helpers.batch_iter(
zip(x_batch, y_batch), FLAGS.batch_size, 1)
t_acc = 0.0
t_acc = float(t_acc)
t_loss = 0.0
t_loss = float(t_loss)
t = 0
f_r = open(file_name, "a+")
step1 = 0
for batch in batches:
x_batch, y_batch = zip(*batch)
feed_dict = {
cnn.input_x: x_batch,
cnn.input_y: y_batch,
cnn.dropout_keep_prob: 1.0
}
step, summaries, loss, accuracy = sess.run(
[global_step, dev_summary_op, cnn.loss, cnn.accuracy],
feed_dict)
time_str = datetime.datetime.now().isoformat()
print("{}: step {}, loss {:g}, acc {:g}".format(time_str, step, loss, accuracy))
t_acc += accuracy
t_loss += loss
t += 1
step1 = step
if writer:
writer.add_summary(summaries, step)
f_r.write(str(step1) + " step " + " accuracy " + str(t_acc/t) + " loss " + str(t_loss/t) + "\n")
print "total ", t_acc/t, "loss", t_loss/t
# Generate batches
评论列表
文章目录