Skip to content

Instantly share code, notes, and snippets.

View jonasrauber's full-sized avatar
🚀

Jonas Rauber jonasrauber

🚀
View GitHub Profile
@aecker
aecker / custom_saver.py
Created November 4, 2016 12:24
Tensorflow custom saver that keeps VGG variables out of checkpoint files
class MySaver(tf.train.Saver):
def __init__(self, var_list, extra_vars=None, extra_chkpt_file=None, **kwargs):
super().__init__(var_list=var_list, **kwargs)
self.extra_chkpt_file = extra_chkpt_file
self.extra_saver = tf.train.Saver(var_list=extra_vars)
def restore(self, sess, save_path):
super().restore(sess, save_path)
self.extra_saver.restore(sess, self.extra_chkpt_file)
@yaroslavvb
yaroslavvb / smart_initialize.py
Created October 13, 2016 23:20
Better initialize_all_variables which respects variable dependencies and doesn't rerun initializers
# testing variable order init
import tensorflow as tf
def initialize_all_variables(sess=None):
"""Initializes all uninitialized variables in correct order. Initializers
are only run for uninitialized variables, so it's safe to run this multiple
times.
Args:
@jbwhit
jbwhit / post-save-hook.py
Last active September 21, 2023 04:50
Saves Jupyter Notebooks as .py and .html files automatically. Add to the ipython_notebook_config.py file of your associated profile.
import os
from subprocess import check_call
def post_save(model, os_path, contents_manager):
"""post-save hook for converting notebooks to .py and .html files."""
if model['type'] != 'notebook':
return # only do this for notebooks
d, fname = os.path.split(os_path)
check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d)
check_call(['jupyter', 'nbconvert', '--to', 'html', fname], cwd=d)