I am relatively new to TensorFlow, and definitely new at TensorBoard and Estimator API. I want to train a slightly modified Resnet model of Tensorflow from a source code I was given, and as the official model it uses Estimator.
I need the test error and accuracy graphs. Accuracy graph is showing me only a dot, and I can’t get test error at all. I also need number of epochs on the x-axis, instead of steps. This is more straightforward to realise with low-level Tensorflow, however I need to use the model I was given.
I create learning_rate, cross_entropy and train_accuracy tensors as below in resnet_fn. I also added SummarySaverHook in resnet_fn. It doesn’t help as well.
def resnet_model_fn(...):
...
tf.identity(learning_rate, name='learning_rate')
tf.summary.scalar('learning_rate', learning_rate)
....
summary_hook = tf.train.SummarySaverHook(
flags.epochs_per_eval,
output_dir=FLAGS.model_dir,
summary_op=tf.summary.merge_all())
return tf.estimator.EstimatorSpec(
mode=mode,
predictions=predictions,
loss=loss,
train_op=train_op,
eval_metric_ops=metrics,
training_hooks=[summary_hook],
evaluation_hooks=[summary_hook])
Here is resnet_main(). I can see those tensors “eval_cross_entropy” etc on my terminal, however they are not shown in TensorBoard at all. I am sharing a screen shot from TensorBoard as well. 
def resnet_main(flags, model_function, input_function):
# Using the Winograd non-fused algorithms provides a small performance boost.
os.environ['TF_ENABLE_WINOGRAD_NONFUSED'] = '1'
# Set up a RunConfig to only save checkpoints once per training cycle.
run_config = tf.estimator.RunConfig().replace(save_checkpoints_secs=1e9, save_summary_steps=flags.epochs_per_eval)
classifier = tf.estimator.Estimator(
model_fn=model_function, model_dir=flags.model_dir, config=run_config,
params={
'resnet_size': flags.resnet_size,
'data_format': flags.data_format,
'batch_size': flags.batch_size,
})
for _ in range(flags.train_epochs // flags.epochs_per_eval):
tensors_to_log = {
'learning_rate': 'learning_rate',
'cross_entropy': 'cross_entropy',
'train_accuracy': 'train_accuracy'
}
logging_hook = tf.train.LoggingTensorHook(
tensors=tensors_to_log, every_n_iter=flags.epochs_per_eval)
print('Starting a training cycle.')
def input_fn_train():
return input_function(True, flags.data_dir, flags.batch_size,
flags.epochs_per_eval, flags.num_parallel_calls)
classifier.train(input_fn=input_fn_train, hooks=[logging_hook])
tensors_to_log_eval = {
'eval_cross_entropy': 'cross_entropy',
'eval_train_accuracy': 'train_accuracy'
}
logging_hook_eval = tf.train.LoggingTensorHook(
tensors=tensors_to_log_eval, every_n_iter=flags.epochs_per_eval)
print('Starting to evaluate.')
# Evaluate the model and print results
def input_fn_eval():
return input_function(False, flags.data_dir, flags.batch_size,
1, flags.num_parallel_calls)
eval_results = classifier.evaluate(input_fn=input_fn_eval, hooks=[logging_hook_eval])
tensors_to_log_pred = {
'pred_cross_entropy': 'cross_entropy'
}
logging_hook_pred = tf.train.LoggingTensorHook(
tensors=tensors_to_log_pred, every_n_iter=flags.epochs_per_eval)
print('Starting to predict.')
def input_fn_pred():
return input_function(False, flags.data_dir, flags.batch_size,
1, flags.num_parallel_calls)
pred_results = classifier.predict(input_fn=input_fn_pred, hooks=[logging_hook_pred])
return eval_results, pred_results
How can I get test error and accuracy graphs with number of epochs on x-axis?