Skip to content

Instantly share code, notes, and snippets.

View joelouismarino's full-sized avatar

Joe Marino joelouismarino

View GitHub Profile
import math
import torch
from torch.distributions import Normal
# standard univariate Gaussian (Normal)
mean = torch.zeros(1)
std = torch.ones(1)
# evaluate from -0.5 to 0.5
x_min = -0.5 * torch.ones(1)
import math
import torch
from torch.distributions import Normal
# standard univariate Gaussian (Normal)
mean = torch.zeros(1)
std = torch.ones(1)
# evaluate at the origin
value = torch.zeros(1)
import numpy as np
def whiten(X, method='zca'):
"""
Whitens the input matrix X using specified whitening method.
Inputs:
X: Input data matrix with data examples along the first dimension
method: Whitening method. Must be one of 'zca', 'zca_cor', 'pca',
import numpy as np
n_samples = 500
mean_1 = 15
std_dev_1 = 5
mean_2 = -20
std_dev_2 = 3
X = np.concatenate([np.random.normal(mean_1, std_dev_1, n_samples / 2),
np.random.normal(mean_2, std_dev_2, n_samples / 2)], axis=0)
import numpy as np
n_samples = 500
mean = 15
std_dev = 5
X = np.random.normal(mean, std_dev, n_samples)
Z = (X - np.mean(X)) / np.std(X)
keras_top_inds = keras_act[0].argsort()[::-1][:5]
zip(keras_act[0][keras_top_inds], labels[keras_top_inds])
labels_file = caffe_root + 'data/ilsvrc12/synset_words.txt'
labels = np.loadtxt(labels_file, str, delimiter='\t')
caffe_top_inds = caffe_act[0].argsort()[::-1][:5]
zip(caffe_act[0][caffe_top_inds], labels[caffe_top_inds])
caffe_act = net.blobs[layer_name].data
layer = googlenet.get_layer(name=layer_name)
keras_act = get_activations(googlenet, layer, img)
import theano
def get_activations(model, layer, X_batch):
get_activations = theano.function([model.layers[0].input,K.learning_phase()], layer.output, allow_input_downcast=True)
activations = get_activations(X_batch,0)
return activations
net.blobs['data'].reshape(1, 3, 224, 224)
net.blobs['data'].data = img
output = net.forward()