Exemple #1
0
def test_zca_dataset():
    """
    Tests the ZCA_Dataset class.
    """
    # Preparation
    rng = np.random.RandomState([2014, 11, 4])
    start = 0
    stop = 990
    num_examples = 1000
    num_feat = 5
    num_classes = 2

    # random_dense_design_matrix has values that are centered and of
    # unit stdev, which is not useful to test the ZCA.
    # So, we replace its value by an uncentered uniform one.
    raw = random_dense_design_matrix(rng, num_examples, num_feat, num_classes)
    x = rng.uniform(low=-0.5, high=2.0, size=(num_examples, num_feat))
    x = x.astype(np.float32)
    raw.X = x

    zca = ZCA(filter_bias=0.0)
    zca.apply(raw, can_fit=True)
    zca_dataset = ZCA_Dataset(raw, zca, start, stop)

    # Testing general behaviour
    mean = zca_dataset.X.mean(axis=0)
    var = zca_dataset.X.std(axis=0)
    assert_allclose(mean, np.zeros(num_feat), atol=1e-2)
    assert_allclose(var, np.ones(num_feat), atol=1e-2)

    # Testing mapback()
    y = zca_dataset.mapback(zca_dataset.X)
    assert_allclose(x[start:stop], y)

    # Testing mapback_for_viewer()
    y = zca_dataset.mapback_for_viewer(zca_dataset.X)
    z = x/np.abs(x).max(axis=0)
    assert_allclose(z[start:stop], y, rtol=1e-2)

    # Testing adjust_for_viewer()
    y = zca_dataset.adjust_for_viewer(x.T).T
    z = x/np.abs(x).max(axis=0)
    assert_allclose(z, y)

    # Testing adjust_to_be_viewed_with()
    y = zca_dataset.adjust_to_be_viewed_with(x, 2*x, True)
    z = zca_dataset.adjust_for_viewer(x)
    assert_allclose(z/2, y)
    y = zca_dataset.adjust_to_be_viewed_with(x, 2*x, False)
    z = x/np.abs(x).max()
    assert_allclose(z/2, y)

    # Testing has_targets()
    assert zca_dataset.has_targets()
def test_zca_dataset():
    """
    Test that a ZCA dataset can be constructed without crashing. No
    attempt to verify correctness of behavior.
    """

    rng = np.random.RandomState([2014, 11, 4])
    num_examples = 5
    dim = 3
    num_classes = 2
    raw = random_dense_design_matrix(rng, num_examples, dim, num_classes)
    zca = ZCA()
    zca.apply(raw, can_fit=True)
    zca_dataset = ZCA_Dataset(raw, zca, start=1, stop=4)
Exemple #3
0
parser.add_argument('-o')

args = parser.parse_args()
model_path = '/data/lisa/exp/wuzhen/conv2d/' + args.folder + '/convolutional_network_best.pkl'

import os
#X = np.load(os.environ['PYLEARN2_DATA_PATH'] + '/faceEmo/test_X.npy')
#y = np.load(os.environ['PYLEARN2_DATA_PATH'] + '/faceEmo/test_y.npy')
#print 'X.shape before', X.shape
X = np.load('test_input.npy')
X = X.astype('float32')
test_set = DenseDesignMatrix(X)

preproc = ZCA()
preproc.fit(test_set.X)
preproc.apply(test_set)
X = test_set.X

X = X.reshape(X.shape[0], 48, 48, 1).astype('float32')

f = open(model_path, 'rb')
mlp = cPickle.load(f)

X_theano = mlp.get_input_space().make_batch_theano()
#X_theano = T.tensor4()
y_theano = mlp.fprop(X_theano)

func = function(inputs=[X_theano], outputs=y_theano)

batch_size = mlp.batch_size
Exemple #4
0
from pylearn2.datasets.mnist import MNIST
train = MNIST(which_set = 'train')
from pylearn2.datasets.preprocessing import ZCA
zca = ZCA()
zca.apply(train, can_fit=True)
from pylearn2.utils import serial
serial.save('mnist_zca.pkl', zca)
Exemple #5
0
from pylearn2.datasets.mnist import MNIST

train = MNIST(which_set='train')
from pylearn2.datasets.preprocessing import ZCA

zca = ZCA()
zca.apply(train, can_fit=True)
from pylearn2.utils import serial

serial.save('mnist_zca.pkl', zca)