Esempio n. 1
0
import sys
from framework.utils import serial
import numpy as N
from theano import function

model = serial.load(sys.argv[1])
model.redo_theano()
dataset = serial.load(sys.argv[2])
X = dataset.get_design_matrix()
output_path = sys.argv[3]

batch_size = 5
nhid = model.get_output_dim()

W = model.W.get_value()
b = model.c.get_value()
beta = function([],model.beta)()
if not model.fold_biases:
    print 'compensating for fancy biases'
    W_norms = N.square(W).sum(axis=0)
    b += beta * (- N.dot(model.vis_mean.get_value(), W) - 0.5 * W_norms )
#

#compensate for beta scaling the responses
W = (W.T * beta).T

print 'making dot products'
dots = N.cast['float32'](N.dot(X,W))
print 'done'

print 'making activations'
Esempio n. 2
0
import sys
from framework.utils import serial
import matplotlib.pyplot as plt

model = serial.load(sys.argv[1])

W = model.W.get_value()


plt.scatter(W[0,:],W[1,:])
plt.show()
Esempio n. 3
0
import sys
import matplotlib.pyplot as plt
from framework.utils import serial
import numpy as N

d = serial.load(sys.argv[1])

dots = N.load(d['dots'])
acts = N.load(d['acts'])
bvec = d['b']

assert dots.shape == acts.shape

print 'overall ave act '+str(acts.mean())
means = acts.mean(axis=0)
print (means.min(),means.max())

plt.hist(means, bins=1000)
plt.show()

print 'waiting'
x = raw_input()
if x == 'q':
    quit()
print 'running'

for i in xrange(dots.shape[1]):
    b = bvec[i]

    plt.hold(False)
    a = acts[:,i]
Esempio n. 4
0
import numpy as N
import sys
from framework.utils import serial
import matplotlib.pyplot as plt
from framework.config import yaml_parse

model = serial.load(sys.argv[1])
model.redo_theano()

#X = N.random.RandomState([1,2,3]).randn(500,2)
dataset = yaml_parse.load(model.dataset_yaml_src)
X = dataset.get_batch_design(500)

while True:
    plt.scatter(X[:, 0], X[:, 1])
    plt.show()

    print 'waiting'

    x = raw_input()
    if x == 'q':
        break

    try:
        niter = int(x)
    except:
        niter = 1

    print 'running'

    for i in xrange(niter):
Esempio n. 5
0
import numpy as N
import sys
from pylearn2.gui import patch_viewer
from pylearn2.config import yaml_parse

assert len(sys.argv) == 2
path = sys.argv[1]

if path.endswith('.pkl'):
    from framework.utils import serial
    dataset = serial.load(path)
elif path.endswith('.yaml'):
    dataset =yaml_parse.load_path(path)
else:
    dataset = yaml_parse.load(path)

rows = 20
cols = 20

examples = dataset.get_batch_topo(rows*cols)

print ('examples range',examples.min(),examples.max(), examples.dtype)

examples /= N.abs(examples).max()

if len(examples.shape) != 4:
    print 'sorry, view_examples.py only supports image examples for now.'
    print 'this dataset has '+str(len(examples)-2)+' topological dimensions'
    quit(-1)
#
Esempio n. 6
0
import sys
from framework.utils import serial
import numpy as N
from theano import function

model = serial.load(sys.argv[1])
model.redo_theano()
dataset = serial.load(sys.argv[2])
X = dataset.get_design_matrix()
output_path = sys.argv[3]

batch_size = 5
nhid = model.get_output_dim()

W = model.W.get_value()
b = model.c.get_value()
beta = function([], model.beta)()
if not model.fold_biases:
    print 'compensating for fancy biases'
    W_norms = N.square(W).sum(axis=0)
    b += beta * (-N.dot(model.vis_mean.get_value(), W) - 0.5 * W_norms)
#

#compensate for beta scaling the responses
W = (W.T * beta).T

print 'making dot products'
dots = N.cast['float32'](N.dot(X, W))
print 'done'

print 'making activations'
Esempio n. 7
0
import sys
import matplotlib.pyplot as plt
from framework.utils import serial
import numpy as N

d = serial.load(sys.argv[1])

dots = N.load(d['dots'])
acts = N.load(d['acts'])
bvec = d['b']

assert dots.shape == acts.shape

print 'overall ave act ' + str(acts.mean())
means = acts.mean(axis=0)
print(means.min(), means.max())

plt.hist(means, bins=1000)
plt.show()

print 'waiting'
x = raw_input()
if x == 'q':
    quit()
print 'running'

for i in xrange(dots.shape[1]):
    b = bvec[i]

    plt.hold(False)
    a = acts[:, i]
Esempio n. 8
0
 def __init__(self, which_set):
     self.underlying = cifar10.CIFAR10(which_set = which_set)
     self.preprocessor = serial.load('/u/goodfeli/framework/recons_srbm/cifar10_preprocessor_2M.pkl')
Esempio n. 9
0
def get_weights_report(model_path, rescale=True):
    print "making weights report"
    print "loading model"
    p = serial.load(model_path)
    print "loading done"

    dataset = yaml_parse.load(p.dataset_yaml_src)

    if "weightsShared" in dir(p):
        p.weights = p.weightsShared.get_value()

    if "W" in dir(p):
        p.weights = p.W.get_value()

    if "D" in dir(p):
        p.decWeightsShared = p.D

    if "enc_weights_shared" in dir(p):
        p.weights = p.enc_weights_shared.get_value()

    if "W" in dir(p) and len(p.W.get_value().shape) == 3:
        W = p.W.get_value()
        nh, nv, ns = W.shape
        pv = patch_viewer.PatchViewer(grid_shape=(nh, ns), patch_shape=dataset.view_shape()[0:2])

        for i in range(0, nh):
            for k in range(0, ns):
                patch = W[i, :, k]
                patch = dataset.vec_to_view(patch, weights=True)
                pv.add_patch(patch, rescale=rescale)
            #
        #
    elif len(p.weights.shape) == 2:
        assert type(p.weights_format()) == type([])
        assert len(p.weights_format()) == 2
        assert p.weights_format()[0] in ["v", "h"]
        assert p.weights_format()[1] in ["v", "h"]
        assert p.weights_format()[0] != p.weights_format()[1]

        if p.weights_format()[0] == "v":
            p.weights = p.weights.transpose()
        h = p.nhid

        hr = int(N.ceil(N.sqrt(h)))
        hc = hr
        if "hidShape" in dir(p):
            hr, hc = p.hidShape

        pv = patch_viewer.PatchViewer(
            grid_shape=(hr, hc), patch_shape=dataset.view_shape()[0:2], is_color=dataset.view_shape()[2] == 3
        )
        weights_mat = p.weights

        assert weights_mat.shape[0] == h
        weights_view = dataset.get_weights_view(weights_mat)
        assert weights_view.shape[0] == h
        # print 'weights_view shape '+str(weights_view.shape)
        for i in range(0, h):
            patch = weights_view[i, ...]
            pv.add_patch(patch, rescale=rescale)
    else:
        e = p.weights
        d = p.dec_weights_shared.value

        h = e.shape[0]

        if len(e.shape) == 8:
            raise Exception("get_weights_report doesn't support tiled convolution yet, use the show_weights8 app")

        if e.shape[4] != 1:
            raise Exception("weights shape: " + str(e.shape))
        shape = e.shape[1:3]
        dur = e.shape[3]

        show_dec = id(e) != id(d)

        pv = PatchViewer.PatchViewer(grid_shape=((1 + show_dec) * h, dur), patch_shape=shape)
        for i in range(0, h):
            pv.addVid(e[i, :, :, :, 0], rescale=rescale)
            if show_dec:
                pv.addVid(d[i, :, :, :, 0], rescale=rescale)

    print "smallest enc weight magnitude: " + str(N.abs(p.weights).min())
    print "mean enc weight magnitude: " + str(N.abs(p.weights).mean())
    print "max enc weight magnitude: " + str(N.abs(p.weights).max())

    return pv