4

I have been using the estimator interface in TF 1.3 including the creation of the data input function:

training_input_fn = tf.estimator.inputs.pandas_input_fn(x=training_data, y=training_label, batch_size=64, shuffle=True, num_epochs=None)

and building the NN:

dnnclassifier = tf.estimator.DNNClassifier( feature_columns=dnn_features, hidden_units=[1024, 500, 100], n_classes=2, model_dir='./tmp/ccsprop', optimizer=tf.train.ProximalAdagradOptimizer( learning_rate=0.001, l1_regularization_strength=0.01 ))

and executing it

dnnclassifier.train(input_fn=training_input_fn, steps=1500)

After much searching I see no easy way to add tensorboard output without resorting to recreating the model from scratch and indicated here https://www.tensorflow.org/extend/estimators

And even then I can find no good examples to follow that both create a simple dnnClassifier with tensorboard output. any guidance?

I have the basic model working but need to examine it much more closely for tuning eventually using experiments as well. Don't see how?

dartdog
  • 10,432
  • 21
  • 72
  • 121

2 Answers2

3

When calling DNNClassifier.train, it accepts hooks parameter, you can create a SummarySaverHook and add it to hooks.

Update

When add a metric (accuracy for example) into TensorBoard, you should flow several steps:

  1. Define a Tensor which calculate the accuracy: acc_op = ...;

  2. Add the Tensor into tf.summary.scalar: tf.summary.scalar('acc', acc_op);

  3. There can be multiple tf.summary in tf.Graph, so we define a merge_summary_op = tf.summary.merge_all() to get an op to merge all the metric Tensors.

  4. Add the merge_summary_op into a summary_writer = tf.summary.FileWriter();

  5. Add the summary_writer into a SummarySaverHook or call the summary_writer by your own code.

Tianjin Gu
  • 784
  • 6
  • 17
  • Any pointer to a sample implementation? Struggling with the doc.. tried to create >TBcall=tf.SummarySaverHook(save_steps=10, output_dir='./tb') get >>AttributeError: module 'tensorflow' has no attribute 'SummarySaverHook' – dartdog Sep 08 '17 at 20:25
  • I got it to take TBcall=tf.train.SummarySaverHook(save_steps=10, output_dir='./tb') but it needs one of scaffold or summary_op, which I don't know how to reference? (And I'd like to get the graph?) – dartdog Sep 08 '17 at 20:37
  • So, further `TBcall=tf.train.SummarySaverHook(save_steps=10, output_dir='./tb', summary_op='accuracy')` and `dnnclassifier.train(input_fn=training_input_fn, steps=1500, hooks=TBcall) ` gives the error: `'SummarySaverHook' object is not iterable` – dartdog Sep 09 '17 at 14:03
  • 1
    hooks should be a list, so hooks = [TBcall] – Tianjin Gu Sep 10 '17 at 10:43
  • But how should the called object be constructed,? I'm getting "Fetch argument 'accuracy' cannot be interpeter as a tensor.. What arguments/functions are accessible in the canned DNN? (my last comment has my attempt. – dartdog Sep 10 '17 at 12:10
  • try `TBcall=tf.train.SummarySaverHook(save_steps=10, output_dir='./tb', summary_op=tf.summary.merge_all())` – Tianjin Gu Sep 10 '17 at 23:13
  • that gives this error: Exactly one of scaffold or summary_op must be provided – dartdog Sep 11 '17 at 14:00
  • It seems your update in the main answer would require writing the model from scratch rather than using the `tf.estimator.DNNClassifier` class? Which was my original question.. Anyhow, posted to GH https://github.com/tensorflow/tensorflow/issues/12974 – dartdog Sep 11 '17 at 17:45
3

See here for an extended discussion on GH: https://github.com/tensorflow/tensorflow/issues/12974#issuecomment-339856673

This does the trick to get a full set of TB output from canned models:

dnnclassifier = tf.estimator.DNNClassifier(
  feature_columns=dnn_features,
  hidden_units=[1024, 500, 100],
  n_classes=2, 
  model_dir='./tmp/ccsprop',
  optimizer=tf.train.ProximalAdagradOptimizer(
    learning_rate=0.001,
    l1_regularization_strength=0.01),
  config=tf.estimator.RunConfig().replace(save_summary_steps=10)
)

Note the last line and be observant of where you need parentheses!

eLillie
  • 653
  • 9
  • 17
dartdog
  • 10,432
  • 21
  • 72
  • 121