Skip to content

Instantly share code, notes, and snippets.

def PReLU(_x, name):
_alpha = tf.get_variable(name, shape=_x.get_shape()[-1],
dtype=_x.dtype, initializer=tf.constant_initializer(0.1))
return tf.maximum(0.0, _x) + _alpha * tf.minimum(0.0, _x)
def batch_normify(batch, depth=1):
"""Returns a normalized batch.
Inputs:
-batch: a batch tensor
-depth: the dimension of the axis you want to keep unnormalized"""
with tf.variable_scope('bn'):
beta = tf.Variable(tf.constant(0.0, shape=[depth]),
name='beta', trainable=True)
gamma = tf.Variable(tf.constant(1.0, shape=[depth]),
name='gamma', trainable=True)
@blorgblerg
blorgblerg / .py
Created July 28, 2017 21:15
Timer decorator for Python
import time
def timeme(some_function):
"""Place above function definition."""
def time_function(*args,**kwargs):
starttime = time.time()
print('Timed: {} s. '.format(time.time() - starttime))
return some_function(*args, **kwargs)
return time_function
import sys
# These are the usual ipython objects, including this one you are creating
ipython_vars = ['In', 'Out', 'exit', 'quit', 'get_ipython', 'ipython_vars']
# Get a sorted list of the objects and their sizes
sorted([(x, sys.getsizeof(globals().get(x))) for x in dir() if not x.startswith('_') and x not in sys.modules and x not in ipython_vars], key=lambda x: x[1], reverse=True)