Skip to content

Instantly share code, notes, and snippets.

View MInner's full-sized avatar

Ben Usman MInner

View GitHub Profile
@MInner
MInner / restore_using_variable_scope.py
Created April 4, 2017 19:01
One way of restoring weights when computation graph structure has changed
# example code for EC500 K1 / CS591 S2 Deep Learning (Spring 2017)
import tensorflow as tf
import numpy as np
def main_save():
with tf.Graph().as_default() as g:
with tf.variable_scope('to_save'):
a = tf.get_variable('a_name', [100, 100])
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MInner
MInner / parallel.py
Last active August 9, 2022 02:14
Executing jobs in parallel with a nice progress bar: a tqdm wrapper for joblib.Parallel
from tqdm import tqdm_notebook as tqdm
from joblib import Parallel, delayed
import time
import random
def func(x):
time.sleep(random.randint(1, 10))
return x
def load_experiment_backup(model_name):
filename = 'h_backup/%s.pickle' % model_name
if os.path.isfile(filename):
with open(filename, 'rb') as handle:
return pickle.load(handle)
else:
return Trials()
def update_experiment_backup(trials, model_name):
with open('h_backup/%s.pickle' % model_name, 'wb') as f:
import tensorflow as tf
import numpy as np
class tnpg:
def __init__(self, tf_arr):
self.arr = tf_arr
def __getitem__(self, idx):
if any([type(x) not in [slice, tf.python.framework.ops.Tensor, list] for x in idx]):
raise ValueError("Unsupported type (not slice, tensor or list)! "
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MInner
MInner / theano_optimization_snippet.ipynb
Last active November 7, 2015 02:13
(Example) Optimization Using Theano
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.