Ejemplo n.º 1
0
    def show(self):
        """
        .. todo::

            WRITEME
        """
        #image.imview_async(self.image)
        show(self.image)
Ejemplo n.º 2
0
def explore(X,y):
    for i in xrange(X.shape[0]):
        patch = X[i,:].reshape(28,28)
        print y[i]
        show(patch)
        x = raw_input('waiting...')
        if x == 'n':
            return
        if x == 'q':
            quit(-1)
Ejemplo n.º 3
0
 def show(self):
     #image.imview_async(self.image)
     show(self.image)
Ejemplo n.º 4
0
r = 6
c = 6
dataset = CIFAR10(which_set = 'train', one_hot = True, gcn = 55.)

ten4 = dataset.get_batch_topo(m)

from pylearn2.utils import sharedX
ten4th = sharedX(ten4)

X = cifar10neighbs(ten4, (r,c))

from theano import function

X = function([],X)()
print X.shape

from pylearn2.gui.patch_viewer import make_viewer
from pylearn2.utils.image import show
stride = (32-r+1)*(32-c+1)

for i in xrange(m):
    ten4v =ten4[i,:,:,:]
    ten4v -= ten4v.min()
    ten4v /= ten4v.max()
    show(ten4v)
    patch_viewer = make_viewer(X[i*stride:(i+1)*stride], is_color= True)
    patch_viewer.show()

    print 'waiting...'
    x = raw_input()
Ejemplo n.º 5
0
 def show(self):
     show(self.image)
Ejemplo n.º 6
0
    H[i*batch_size:(i+1)*batch_size,:] = f(X)


h = H.mean(axis=0)
proj = np.dot(H,h)

#sort examples by projection along the mean vector
ranking = sorted(zip(proj,range(proj.shape[0])))

new_H = H.copy()

for i, t in enumerate(ranking):
    new_H[i,:] = H[t[1],:]
H = new_H

#sort units by mean activation
ranking = sorted(zip(h,range(h.shape[0])))

new_H = H.copy()

for i, t in enumerate(ranking):
    new_H[:,i] = H[:,t[1]]
H = new_H



from pylearn2.utils import image

image.show(H)

Ejemplo n.º 7
0
import numpy as np

from pylearn2.utils import image

imbase = '/data/lisatmp/goodfeli/esp/final_images'
ims = sorted(os.listdir(imbase))


for label, im in zip(labels, ims):

    stem = label.split('.')[0]
    assert stem in im

    img = image.load(imbase + '/' + im)

    image.show(img)

    full_label_path = labels_dir + '/' + label
    print 'True labels:'
    fd = open(full_label_path,'r')
    print fd.read()
    fd.close()

    full_l2_path = l2_path + '/' + label.split('.')[0] + '.npy'

    l2 = np.load(full_l2_path)

    y = f(l2)

    print 'Predicted labels: '
    print y.shape
Ejemplo n.º 8
0
f = function([X], features)

for i in xrange(num_batches):
    X = dataset.get_batch_design(batch_size)
    H[i * batch_size:(i + 1) * batch_size, :] = f(X)

h = H.mean(axis=0)
proj = np.dot(H, h)

#sort examples by projection along the mean vector
ranking = sorted(zip(proj, range(proj.shape[0])))

new_H = H.copy()

for i, t in enumerate(ranking):
    new_H[i, :] = H[t[1], :]
H = new_H

#sort units by mean activation
ranking = sorted(zip(h, range(h.shape[0])))

new_H = H.copy()

for i, t in enumerate(ranking):
    new_H[:, i] = H[:, t[1]]
H = new_H

from pylearn2.utils import image

image.show(H)
Ejemplo n.º 9
0
l2_path = '/data/lisatmp/goodfeli/esp/final_l2'
import numpy as np

from pylearn2.utils import image

imbase = '/data/lisatmp/goodfeli/esp/final_images'
ims = sorted(os.listdir(imbase))

for label, im in zip(labels, ims):

    stem = label.split('.')[0]
    assert stem in im

    img = image.load(imbase + '/' + im)

    image.show(img)

    full_label_path = labels_dir + '/' + label
    print 'True labels:'
    fd = open(full_label_path, 'r')
    print fd.read()
    fd.close()

    full_l2_path = l2_path + '/' + label.split('.')[0] + '.npy'

    l2 = np.load(full_l2_path)

    y = f(l2)

    print 'Predicted labels: '
    print y.shape
Ejemplo n.º 10
0
 def show(self):
     #image.imview_async(self.image)
     show(self.image)
Ejemplo n.º 11
0
r = 6
c = 6
dataset = CIFAR10(which_set='train', one_hot=True, gcn=55.)

ten4 = dataset.get_batch_topo(m)

from pylearn2.utils import sharedX
ten4th = sharedX(ten4)

X = cifar10neighbs(ten4, (r, c))

from theano import function

X = function([], X)()
print X.shape

from pylearn2.gui.patch_viewer import make_viewer
from pylearn2.utils.image import show
stride = (32 - r + 1) * (32 - c + 1)

for i in xrange(m):
    ten4v = ten4[i, :, :, :]
    ten4v -= ten4v.min()
    ten4v /= ten4v.max()
    show(ten4v)
    patch_viewer = make_viewer(X[i * stride:(i + 1) * stride], is_color=True)
    patch_viewer.show()

    print 'waiting...'
    x = raw_input()
Ejemplo n.º 12
0
grad = T.grad(g, X)

step_X = X + alpha * grad

norm = T.sqrt(T.sqr(X).sum())

renormed_X = step_X  #/ norm

from theano import function

f = function([], [g, norm], updates={X: renormed_X})

while True:
    a, b = f()

    print a, ' ', b

    if a > .75:
        break

from pylearn2.utils import image
from pylearn2.config import yaml_parse

dataset = yaml_parse.load(dataset_yaml_src)

X = dataset.get_topological_view(X.get_value())

X /= np.abs(X).max()

image.show(X[0, ...])
Ejemplo n.º 13
0
act = p[0,filter_idx,i,j]

obj = - act + norm_penalty * T.square(X).sum()

assert obj.ndim == 0

optimizer = BatchGradientDescent(objective = obj,
        params = [X],
        inputs = None,
        param_constrainers = None,
        max_iter = 1000,
        verbose = True,
        tol = None,
        init_alpha = (.001, .005, .01, .05, .1))

optimizer.minimize()

img = X.get_value()[0,:,:,:]

print 'max mag: ',np.abs(img).max()
print 'norm: ',np.square(img).sum()
print 'min: ',img.min()
print 'max: ',img.max()

img /= np.abs(img).max()

img *= .5
img += 1

show(img)
Ejemplo n.º 14
0
    for j in xrange(mr):
        for k in xrange(mc):
            r = 0.
            g = 0.
            b = 0.
            r_count = 0
            g_count = 0
            b_count = 0

            for l in xrange(ch):
                elem = convmap[i,j,k,l]

                if elem < 32:
                    r_count += 1
                    r += float(elem)/31.
                if elem >= 32 and elem < 64:
                    g_count += 1
                    g += float(elem-32)/31.
                if elem >= 64:
                    b_count += 1
                    b += float(elem-64)/float(m)
            decoded_map[i,j,k,:] = np.asarray( [ r/(1e-12+float(r_count)),
                                                 g/(1e-12+float(g_count)),
                                                 b/(1e-12+float(b_count))])

for  i in xrange(m):
    show(decoded_img[i,:,:,:])
    show(decoded_map[i,:,:,:])

    x = raw_input()
Ejemplo n.º 15
0
norm =  T.sqrt(T.sqr(X).sum())

renormed_X = step_X #/ norm

from theano import function

f = function([],[g,norm],updates = { X : renormed_X })

while True:
    a,b =  f()

    print a,' ',b

    if a > .75:
        break

from pylearn2.utils import image
from pylearn2.config import yaml_parse

dataset = yaml_parse.load( dataset_yaml_src )

X = dataset.get_topological_view( X.get_value())

X /= np.abs(X).max()

image.show(X[0,...])



Ejemplo n.º 16
0
from pylearn2.optimization.batch_gradient_descent import BatchGradientDescent

bgd = BatchGradientDescent(objective=-neuron,
        params=[X],
        inputs=None,
        max_iter=100,
        lr_scalers=None,
        verbose=3,
        tol=None,
        init_alpha=None,
        min_init_alpha=1e-3,
        reset_alpha=True,
        conjugate=True,
        gradients=None,
        gradient_updates=None,
        accumulate=False,
        theano_function_mode=None,
        param_constrainers=None)

bgd.minimize()


X = normed.eval()[:,:,:,0].transpose(1,2,0)
import numpy as np
X /= np.abs(X).max()
print (X.min(), X.max())

from pylearn2.utils.image import show
show(X)