Skip to content

Instantly share code, notes, and snippets.

View JossWhittle's full-sized avatar
😸

Joss Whittle JossWhittle

😸
View GitHub Profile
def spectral_normalization(W, num_iters=1, name='spectral_normalization'):
with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
def l2_normalize(v, eps=1e-12):
return v / (tf.reduce_sum(v ** 2) ** 0.5 + eps)
# Usually num_iters = 1 will be enough
W_shape = W.shape.as_list()
W_reshaped = tf.reshape(W, [-1, W_shape[-1]])
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JossWhittle
JossWhittle / imagenet1000_clsid_to_human.txt
Created April 9, 2018 18:33 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class id to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JossWhittle
JossWhittle / initializers.py
Last active April 4, 2018 19:03
Cleaned up versions of Tensorflow's default weight initialization schemes, extracted from deep within the Tensorflow source code.
He_gain = 2.0
He_n = (fan_in * (kernel_size ** 2))
# Most stable performance in my experience.
He_c_trunc_norm = np.sqrt(1.3 * He_gain / He_n)
He_normal_init = tf.initializers.truncated_normal(stddev=He_c_trunc_norm)
He_c_uniform = np.sqrt(3.0 * He_gain / He_n)
He_uniform_init = tf.initializers.random_uniform(minval=-He_c_uniform, maxval=He_c_uniform)
from IPython.lib.backgroundjobs import BackgroundJobManager
from IPython.core.magic import register_line_magic
from IPython.display import display
from IPython import get_ipython
from itertools import islice, chain
from ipywidgets import IntProgress, HTML, VBox
# Iterate through a generator without peaking, yeilding a list of elements
#
def chunks(iterable, size):
"""
This is a module to convert between one dimensional distance along a
`Hilbert curve`_, :math:`h`, and N-dimensional coordinates,
:math:`(x_0, x_1, ... x_N)`. The two important parameters are :math:`N`
(the number of dimensions, must be > 0) and :math:`p` (the number of
iterations used in constructing the Hilbert curve, must be > 0).
We consider an N-dimensional `hypercube`_ of side length :math:`2^p`.
This hypercube contains :math:`2^{N p}` unit hypercubes (:math:`2^p` along
each dimension). The number of unit hypercubes determine the possible
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.