import os
if os.path.exists(out_path):
    usage()
    print out_path+" already exists, and I don't want to overwrite anything just to be safe."
    quit(-1)

from pylearn2.utils import serial
try:
    model = serial.load(model_path)
except Exception, e:
    usage()
    print model_path + "doesn't seem to be a valid model path, I got this error when trying to load it: "
    print e

dataset = ContestDataset(which_set='public_test',
            base_path = '../data',
            preprocessor = Standardize(),
            fit_preprocessor = True)

dataset = dataset.get_test_set()

# use smallish batches to avoid running out of memory
batch_size = 64
model.set_batch_size(batch_size)
# dataset must be multiple of batch size of some batches will have
# different sizes. theano convolution requires a hard-coded batch size
m = dataset.X.shape[0]
extra = batch_size - m % batch_size
assert (m + extra) % batch_size == 0
import numpy as np
if extra > 0:
    dataset.X = np.concatenate((dataset.X, np.zeros((extra, dataset.X.shape[1]),
Ejemplo n.º 2
0
import os
if os.path.exists(out_path):
    usage()
    print out_path+" already exists, and I don't want to overwrite anything just to be safe."
    quit(-1)

from pylearn2.utils import serial
try:
    model = serial.load(model_path)
except Exception, e:
    usage()
    print model_path + "doesn't seem to be a valid model path, I got this error when trying to load it: "
    print e

dataset = ContestDataset(which_set='public_test',
            base_path = '../data',
            preprocessor = Standardize())

dataset = dataset.get_test_set()

X = model.get_input_space().make_batch_theano()
Y = model.fprop(X, apply_dropout=False)

from theano import tensor as T

y = T.argmax(Y, axis=1)

from theano import function

y = function([X], y)(dataset.X.astype(X.dtype))