예제 #1
0
파일: train.py 프로젝트: jaberg/pylearn
 def save(self):
     #TODO-- save state of dataset and training algorithm so training can be resumed after a crash
     if self.save_path is not None:
         print 'saving to '+self.save_path
         serial.save(self.save_path, self.model)
예제 #2
0
#replicate the preprocessing described in Kai Yu's paper Improving LCC with Local Tangents
from framework.utils import serial
from framework.datasets import cifar10
from framework.datasets import preprocessing

train = cifar10.CIFAR10(which_set="train",center=True)

pipeline = preprocessing.Pipeline()
pipeline.items.append(preprocessing.GlobalContrastNormalization(subtract_mean=False,std_bias=0.0))
pipeline.items.append(preprocessing.PCA(num_components=512))

test = cifar10.CIFAR10(which_set="test")

train.apply_preprocessor(preprocessor = pipeline, can_fit = True)
test.apply_preprocessor(preprocessor = pipeline, can_fit = False)

serial.save('cifar10_preprocessed_train.pkl',train)
serial.save('cifar10_preprocessed_test.pkl',test)


예제 #3
0
from framework.utils import serial
from framework.datasets import cifar10
from framework.datasets import preprocessing

train = cifar10.CIFAR10(which_set="train")

pipeline = preprocessing.Pipeline()
pipeline.items.append(preprocessing.ExtractPatches(patch_shape=(8,8),num_patches=200000))
pipeline.items.append(preprocessing.GlobalContrastNormalization())
pipeline.items.append(preprocessing.ZCA())

train.apply_preprocessor(preprocessor = pipeline, can_fit = True)

serial.save('preprocessor.pkl',pipeline)
예제 #4
0
    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'
acts = N.cast['float32'](N.zeros((X.shape[0],nhid)))

for i in xrange(0,X.shape[0],batch_size):
    if i % 1000 == 0:
        print i
    cur_batch_size = min(batch_size, X.shape[0]-batch_size+1)

    acts[i:i+cur_batch_size,:] = model.hid_exp_func(X[i:i+cur_batch_size,:])

print 'saving data'

dots_path = output_path + '_dots.npy'
acts_path = output_path + '_acts.npy'

N.save(dots_path, dots)
N.save(acts_path, acts)

serial.save(output_path+'.pkl',{ 'dots' : dots_path, 'acts' : acts_path, 'b' : b , 'beta' : beta} )
예제 #5
0
from framework.utils import serial
from framework.datasets import cifar10
from framework.datasets import preprocessing

train = cifar10.CIFAR10(which_set="train")

pipeline = preprocessing.Pipeline()
pipeline.items.append(
    preprocessing.ExtractPatches(patch_shape=(8, 8), num_patches=150000))
pipeline.items.append(preprocessing.GlobalContrastNormalization())
pipeline.items.append(preprocessing.ZCA())

test = cifar10.CIFAR10(which_set="test")

train.apply_preprocessor(preprocessor=pipeline, can_fit=True)
test.apply_preprocessor(preprocessor=pipeline, can_fit=False)

train.use_design_loc('cifar10_preprocessed_train_design.npy')
test.use_design_loc('cifar10_preprocessed_test_design.npy')

serial.save('cifar10_preprocessed_train.pkl', train)
serial.save('cifar10_preprocessed_test.pkl', test)
예제 #6
0
train.apply_preprocessor(
    preprocessing.ExtractPatches(patch_shape=(8, 8), num_patches=150000))

orig_patches = train.get_topological_view().copy()
print(orig_patches.min(), orig_patches.max())
#orig_patches -= 0.5
orig_patches -= 127.5
orig_patches /= N.abs(orig_patches).max()
print(orig_patches.min(), orig_patches.max())

train.apply_preprocessor(
    preprocessing.GlobalContrastNormalization(std_bias=10.))

processed_patches = train.get_topological_view().copy()
processed_patches /= N.abs(processed_patches).max()

train.apply_preprocessor(preprocessing.ZCA(), can_fit=True)

zca_patches = train.get_topological_view().copy()
zca_patches /= N.abs(zca_patches).max()

print id(zca_patches)
print id(processed_patches)
print N.abs(zca_patches - processed_patches).mean()

concat = N.concatenate((orig_patches, processed_patches, zca_patches), axis=2)

train.set_topological_view(concat)

serial.save('debug.pkl', train)
예제 #7
0
print 'making dot products'
dots = N.cast['float32'](N.dot(X, W))
print 'done'

print 'making activations'
acts = N.cast['float32'](N.zeros((X.shape[0], nhid)))

for i in xrange(0, X.shape[0], batch_size):
    if i % 1000 == 0:
        print i
    cur_batch_size = min(batch_size, X.shape[0] - batch_size + 1)

    acts[i:i + cur_batch_size, :] = model.hid_exp_func(X[i:i +
                                                         cur_batch_size, :])

print 'saving data'

dots_path = output_path + '_dots.npy'
acts_path = output_path + '_acts.npy'

N.save(dots_path, dots)
N.save(acts_path, acts)

serial.save(output_path + '.pkl', {
    'dots': dots_path,
    'acts': acts_path,
    'b': b,
    'beta': beta
})
예제 #8
0
orig_patches = train.get_topological_view().copy()
print (orig_patches.min(),orig_patches.max())
#orig_patches -= 0.5
orig_patches -= 127.5
orig_patches /= N.abs(orig_patches).max()
print (orig_patches.min(),orig_patches.max())

train.apply_preprocessor(preprocessing.GlobalContrastNormalization(std_bias=10.))


processed_patches = train.get_topological_view().copy()
processed_patches /= N.abs(processed_patches).max()

train.apply_preprocessor(preprocessing.ZCA(), can_fit = True)

zca_patches = train.get_topological_view().copy()
zca_patches /= N.abs(zca_patches).max()

print id(zca_patches)
print id(processed_patches)
print N.abs(zca_patches-processed_patches).mean()

concat = N.concatenate((orig_patches,processed_patches,zca_patches),axis=2)

train.set_topological_view(concat)


serial.save('debug.pkl',train)


예제 #9
0
from framework.utils import serial
from framework.datasets import cifar10
from framework.datasets import preprocessing

train = cifar10.CIFAR10(which_set="train")

pipeline = preprocessing.Pipeline()
pipeline.items.append(preprocessing.ExtractPatches(patch_shape=(8,8),num_patches=2000000))
pipeline.items.append(preprocessing.GlobalContrastNormalization())
pipeline.items.append(preprocessing.ZCA())

test = cifar10.CIFAR10(which_set="test")

train.apply_preprocessor(preprocessor = pipeline, can_fit = True)

serial.save('cifar10_preprocessor_2M.pkl',train)