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_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
@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 / 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)
"""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 / 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
@annarailton
annarailton / pre-commit-autoflake.py
Last active September 20, 2020 19:10
Run autoflake against staged .py files on commit
#!/usr/bin/python3
"""Runs autoflake on commit. Blocks commit and requests adding changed files
if autoflake fires.
Installation
------------
1. You will need to install autoflake: https://pypi.org/project/autoflake/
$ pip install --upgrade autoflake
or
@annarailton
annarailton / update_sublime.sh
Last active December 14, 2018 14:47
Script to keep sublime up to date
# To be run in sudo's crontab. Access via sudo crontab -e
# You need to pick a channel first:
# $ echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
# OR
# $ echo "deb https://download.sublimetext.com/ apt/dev/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
echo $(date)
apt-get update && apt-get install sublime-text
apt autoremove -y
@annarailton
annarailton / .bashrc
Last active August 23, 2019 15:49
Useful .bashrc aliases etc.
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=5000
HISTFILESIZE=10000
# Setup default editor
export EDITOR=subl
# Start ssh agent so can ssh to Git
eval "$(ssh-agent -s)"
@annarailton
annarailton / dump_object_example.py
Created January 4, 2019 11:00
Object that periodically dumps new contents to disk
#!/usr/bin/python3
"""
Toy example using DumpObject, a way of periodically dumping out large objects to
file as it grows. This example watches a file directory and creates a dictionary
with
* key: file name
* value: first line of file
Includes use of `watchdog` to watch for real time effects (here: new files
being created in the directory) and `atexit` to gracefully deal with the program
@annarailton
annarailton / pre-commit-filesize.py
Last active January 29, 2019 12:21
Warns users if staged files are larger than some limit
#!/usr/bin/python3
"""
Checks file size of committed files. If there are stage files bigger than a
given size (`WARN_SIZE_MB`) then
* the commit is aborted
* you are told about the offending files
* you are told the command for forcing through the commit anyway
Save this file as "pre-commit" in your .git/hooks folder and do