Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Change avg_stones to histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
sethtroisi committed Sep 28, 2019
1 parent f194b0b commit 65f873a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dual_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def model_fn(features, labels, mode, params):

# Computations to be executed on CPU, outside of the main TPU queues.
def eval_metrics_host_call_fn(
features,
avg_stones, avg_stones_delta,
policy_output, value_output,
pi_tensor, value_tensor,
policy_cost, value_cost,
Expand All @@ -309,8 +309,6 @@ def eval_metrics_host_call_fn(

value_cost_normalized = value_cost / params['value_cost_weight']
avg_value_observed = tf.reduce_mean(value_tensor)
avg_stones_black = tf.reduce_mean(tf.reduce_sum(features[:,:,:,1], [1,2]))
avg_stones_white = tf.reduce_mean(tf.reduce_sum(features[:,:,:,0], [1,2]))

with tf.variable_scope('metrics'):
metric_ops = {
Expand All @@ -329,8 +327,7 @@ def eval_metrics_host_call_fn(
'policy_target_top_1_confidence': tf.metrics.mean(
policy_target_top_1_confidence),
'avg_value_observed': tf.metrics.mean(avg_value_observed),
'avg_stones_black': tf.metrics.mean(avg_stones_black),
'avg_stones_white': tf.metrics.mean(avg_stones_white),
'avg_stones': tf.metrics.mean(tf.reduce_mean(avg_stones)),
}

if est_mode == tf.estimator.ModeKeys.EVAL:
Expand All @@ -348,6 +345,8 @@ def eval_metrics_host_call_fn(
for metric_name, metric_op in metric_ops.items():
summary.scalar(metric_name, metric_op[1], step=eval_step)

summary.histogram("avg_stones_delta", avg_stones_delta)

# Reset metrics occasionally so that they are mean of recent batches.
reset_op = tf.variables_initializer(tf.local_variables('metrics'))
cond_reset_op = tf.cond(
Expand All @@ -357,8 +356,14 @@ def eval_metrics_host_call_fn(

return summary.all_summary_ops() + [cond_reset_op]

# compute here to avoid sending all of features to cpu.
avg_stones_black = tf.reduce_sum(features[:,:,:,1], [1,2])
avg_stones_white = tf.reduce_sum(features[:,:,:,0], [1,2])
avg_stones = avg_stones_black + avg_stones_white
avg_stones_delta = avg_stones_black - avg_stones_white

metric_args = [
features,
avg_stones, avg_stones_delta,
policy_output,
value_output,
labels['pi_tensor'],
Expand Down

0 comments on commit 65f873a

Please sign in to comment.