6

I am currently trying to predict the movement of a particle using a tensorflow premade Estimator (tf.estimator.DNNRegressor).

I want to save an image of the average loss plot, like the one tensorboard displays, into each model's folder.Image from tensorboard

Tensorboard is pretty good to monitor this during training, but I want to save an image for future reference (e.g. comparing different approaches visually)

Is there an easy way to do this? I could save the results of the evaluation at different times and use matplotlib, but I haven't found anything on how to get the loss from the regressor.train method.

Strandtasche
  • 108
  • 2
  • 9
  • 2
    Not actual solutions, but alternatives. 1) You can download the data in JSON/CSV (check "Show data download links" in upper-left corner) and plot it with Excel/Pandas/etc. 2) Someone wrote [exportTensorFlowLog](https://github.com/anderskm/exportTensorFlowLog) to solve this problem (didn't test it myself) 3) Browser developer tools let you to take screenshots of specific elements (e.g. [Chrome](https://developers.google.com/web/updates/2017/08/devtools-release-notes#node-screenshots), [Firefox](https://developer.mozilla.org/en-US/docs/Tools/Taking_screenshots#Taking_a_screenshot_of_an_element)) – jdehesa Jun 28 '18 at 09:57
  • 3
    exportTensorFlowLog works well for me - I'd recommend it – Strandtasche Aug 28 '18 at 09:14

2 Answers2

10

Yes, currently, you can download the .svg of loss/other_metric history as @Jdehesa pointed out in the comment:

  1. Check Show data download links;

  2. You can see a download symbol on the bottom of the figure;

  3. See the yellow marks in the figure if you can't locate them.

image

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Nymeria94
  • 101
  • 1
  • 5
3

If you would like to do it programmatically, you could combine the CSVLogger and a custom callback for plotting:

class CustomCallbackPlot(Callback):

def __init__(self, training_data_dir):
    self.tdr = training_data_dir

def on_epoch_end(self, epoch, logs=None):
    df_loan = pd.read_csv(os.path.join(self.tdr, 'training_metrics.csv'))
    df_loan[['loss', 'val_loss']].plot()
    plt.xlabel('epochs')
    plt.title('train/val loss')
    plt.savefig(os.path.join(self.tdr, 'training_metrics.png'))

use the CSVLogger callback to first generate the training and validation loss data. After that use this CustomCallbackPlot to plot it.

    csv_logger = CSVLogger(os.path.join(self.training_data_dir, 'training_metrics.csv'))
    callbacks = [csv_logger, CustomCallbackPlot(self.training_data_dir)]

in my example I use the training_data_dir to store the path.

B.Kocis
  • 1,954
  • 20
  • 19