Skip to content

Instantly share code, notes, and snippets.

View annarailton's full-sized avatar

Anna Railton annarailton

View GitHub Profile
@annarailton
annarailton / tensorboard_summary_custom.py
Created August 2, 2018 10:29
Plot two different metrics on the same plot in Tensorboard
# View graphs with (Linux): $ tensorboard --logdir=/tmp/my_tf_model
import os
import tempfile
import tensorflow as tf
import numpy as np
from tensorboard import summary as summary_lib
from tensorboard.plugins.custom_scalar import layout_pb2
"""Simple example of various types of Tensorflow profiling.
Adapted from:
https://towardsdatascience.com/howto-profile-tensorflow-1a49fb18073d
https://www.tensorflow.org/api_docs/python/tf/profiler/Profiler
"""
from __future__ import absolute_import
from __future__ import division
@annarailton
annarailton / tf_save_restore_iterator2.py
Last active May 29, 2021 08:31
Save and restore a Tensorflow model with a tf.data.Dataset + initialisable iterators.
# Tensorflow 1.8.0
import tensorflow as tf
import numpy as np
def make_iterators(train_dataset, test_dataset):
"""Creates the dataset iterators needed in train()."""
handle = tf.placeholder(tf.string, shape=[])
tf.add_to_collection('handle', handle)
@annarailton
annarailton / tf_save_restore_iterator1.py
Created June 22, 2018 10:02
Save and restore a Tensorflow model with a tf.data.Dataset + one_shot_iterator()
# Tensorflow 1.8.0
import tensorflow as tf
import numpy as np
def save(dataset):
"""
Create graph with an Dataset and Iterator and save the model.
There is some op that is applied to the data from the iterator.
"""
@annarailton
annarailton / tensorboard_summary_example.py
Last active June 22, 2018 09:13
Tensorboard summary example
"""MWE of a tensorboard setup with
- a dummy training and validation op
- loss for training and validation shown on the same graph
- histograms showing weights changing with training
To run tensorboard after running this script
$ tensorboard --log_dir=/tmp/tensorboard_demo