This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |