Skip to content

Instantly share code, notes, and snippets.

N-McA

  • Cambridge University
Block or report user

Report or block N-McA

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View install-hooks.py
#!/usr/bin/env python3
import subprocess
import shlex
import os
from pathlib import Path
def chdir_to_script_location():
abspath = os.path.abspath(__file__)
View python-bash-replacement.py
#!/usr/bin/env python3
import subprocess
import shlex
import os
from pathlib import Path
def chdir_to_script_location():
abspath = os.path.abspath(__file__)
View install-hooks.py
#!/usr/bin/env python3
import subprocess
import shlex
import os
from pathlib import Path
def chdir_to_script_location():
abspath = os.path.abspath(__file__)
View erc20-decimals-conversion.js
function isString(s) {
return (typeof s === 'string' || s instanceof String)
}
export function toBaseUnit(value, decimals, BN) {
if (!isString(value)) {
throw new Error('Pass strings to prevent floating point precision issues.')
}
const ten = new BN(10);
const base = ten.pow(new BN(decimals));
@N-McA
N-McA / keras_spatial_bias.py
Last active Jul 13, 2018
Concatenates the (x, y) coordinate normalised to 0-1 to each spatial location in the image. Allows a network to learn spatial bias. Has been explored in at least one paper, "An Intriguing Failing of Convolutional Neural Networks and the CoordConv Solution" https://arxiv.org/abs/1807.03247
View keras_spatial_bias.py
import keras.backend as kb
from keras.layers import Layer
def _kb_linspace(num):
num = kb.cast(num, kb.floatx())
return kb.arange(0, num, dtype=kb.floatx()) / (num - 1)
def _kb_grid_coords(width, height):
w, h = width, height
View tensorflow_pca.py
def tf_pca(x):
'''
Compute PCA on the bottom two dimensions of x,
eg assuming dims = [..., observations, features]
'''
# Center
x -= tf.reduce_mean(x, -2, keepdims=True)
# Currently, the GPU implementation of SVD is awful.
# It is slower than moving data back to CPU to SVD there
@N-McA
N-McA / multi_jpg.py
Last active Apr 27, 2018
Trade memory for time when holding big stack of jpgs
View multi_jpg.py
'''
Compatible with Keras, faster than reading from files (no stats).
It's only designed to work if all your images are vaguely similar sizes/
when encoded as JPGS, so if you have:
white noise or other hard-to-encode stuff
radically varying image sizes
...
(probably other failure modes)
Then this is foolhardy.
View keras_tikz.py
header = r'''
\begin{tikzpicture}[node distance = 2mm, auto]
%% Auto Generated
'''
raw_b = r'''
\node [block, below= of glove] (conv1) {
\begin{tabular}{cc}
Conv1D & Input: $n$x100 \\
64x5 Dilation 1 & Output: $n$x64 \\
View perceptual_matplotlib_centering.py
def get_perceptual_axis_center_in_figure_space(fig, ax):
xs = ax.get_xlim()
if ax.get_xscale() == 'log':
xs = np.log10(xs)
c_x = sum(xs) / 2
c_x = 10**c_x
else:
c_x = sum(xs) / 2
View convert_stanford_to_npy.py
import numpy as np
from pathlib import Path
import h5py
def resolve_name(f, name_ref):
return ''.join([chr(i) for i in f[name_ref]])
def flat(x):
You can’t perform that action at this time.