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.
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.
You can use tensorboardX and import SummaryWriter to write scalars. Try to open the tensorboard server in google chrome (make sure you checked the Show data links) and you will have an option to download the current graph as svg file.
Just check the "Data download links" option on the upper-left in TensorBoard, and then click on the "CSV" button that will appear under your scalar summary.
You can zoom in TensorBoard by dragging on the chart. You can also make the display larger by pressing the small blue box in the lower-left corner of the chart.
Yes, currently, you can download the .svg
of loss/other_metric history as @Jdehesa pointed out in the comment:
Check Show data download links
;
You can see a download symbol on the bottom of the figure;
See the yellow marks in the figure if you can't locate them.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With