GWa
GWa

Reputation: 43

Modify how a tf.estimator.Estimator creates summaries for Tensorboard

I'm trying to find out how I can modify the way a custom TensorFlow estimator creates event files for Tensorboard. Currently, I have the impression that, by default, a summary (containing the values of all the things (like typically accuracy) I'm following with tf.summary.scalar(...) ) is created every 100 steps in my model directory. The names of the event files later used by tensorboard look like events.out.tfevents.1531418661.nameofmycomputer.

I found a routine online to change this behaviour and create directories for each run with the date and time of the computation, but it uses TensorFlow basic APIs:

logdir = "tensorboard/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + "/"
writer = tf.summary.FileWriter(logdir, sess.graph)

Is it possible to do something similar with a TF custom estimator?

Upvotes: 1

Views: 1363

Answers (2)

katsu
katsu

Reputation: 654

It is possible to specify a directory for each evaluation run using name argument of the evaluate method of tf.estimator.Estimator e.g.:

estimator = tf.estimator.Estimator(
    model_fn=model_fn,
    model_dir=model_dir
)
eval_results = estimator.evaluate(
            input_fn=eval_input_fn,
            name=eval_name
            )

The event files for this evaluation will be saved in the directory inside model_dir named "eval_" + eval_name.

Upvotes: 2

Ekaba Bisong
Ekaba Bisong

Reputation: 2982

Summary Writers are not needed for TensorFlow Estimators. The summary log of the model is written to the designated folder location using the model_dir attribute of tf.Estimator function when the tf.Estimator.fit() method is called.

In the example below, the selected directory to store the training logs is './my_model'.

tf.estimator.DNNClassifier(
    model_fn,
    model_dir='./my_model',
    config=None,
    params=None,
    warm_start_from=None
)

Launch TensorBoard by running tensorboard --logdir=./my_model from the terminal.

Upvotes: -1

Related Questions