def __init__(self,which_set,numclass, base_path = '/data/vision/billf/manifold-learning/DL/Data/icml_2013_emotions', start = 0, stop = -1, options = [0], axes = ('b', 0, 1, 'c'), fit_test_preprocessor = False, ): files = {'train': 'train.csv', 'public_test' : 'test.csv'} try: file_path = files[which_set] except KeyError: raise ValueError("Unrecognized dataset name: " + which_set) X, y = self.loadFile(base_path + '/' + file_path, start,stop) # train_index if flip: X_list_flipLR, X_list_flipUD = self.flipData(X) X = X + X_list_flipLR y = y + y view_converter = DefaultViewConverter(shape=(48,48,1), axes=axes) super(ICML_emotion, self).__init__(X=X, y=self.label_id2arr(y,numclass), view_converter=view_converter) if options[0] == 1: fit_preprocessor = False from pylearn2.datasets.preprocessing import GlobalContrastNormalization preprocessor = GlobalContrastNormalization(sqrt_bias = 10,use_std = 1) preprocessor.apply(self, can_fit=fit_preprocessor)
def preprocess(self): pre = GlobalContrastNormalization(sqrt_bias=10, use_std=1) self = pre.apply(self)
def preprocess(self): pre = GlobalContrastNormalization(sqrt_bias = 10,use_std = 1) self = pre.apply(self)
def make_majority_vote(): model_paths = ['convnet_' + str(i + 1) + '.pkl' for i in range(10)] out_path = 'submission.csv' models = [] for model_path in model_paths: print('Loading ' + model_path + '...') try: with open(model_path, 'rb') as f: models.append(pkl.load(f)) except Exception as e: try: with gzip.open(model_path, 'rb') as f: models.append(pkl.load(f)) except Exception as 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) # load the test set with open('test_data_for_pylearn2.pkl', 'rb') as f: dataset = pkl.load(f) dataset = DenseDesignMatrix(X=dataset, view_converter=DefaultViewConverter( shape=[32, 32, 1], axes=['b', 0, 1, 'c'])) preprocessor = GlobalContrastNormalization(subtract_mean=True, sqrt_bias=0.0, use_std=True) preprocessor.apply(dataset) predictions = [] print('Model description:') print('') print(models[1]) print('') for model in models: model.set_batch_size(dataset.X.shape[0]) X = model.get_input_space().make_batch_theano() Y = model.fprop(X) # forward prop the test data y = T.argmax(Y, axis=1) f = function([X], y) x_arg = dataset.get_topological_view() y = f(x_arg.astype(X.dtype)) assert y.ndim == 1 assert y.shape[0] == dataset.X.shape[0] # add one to the results! y += 1 predictions.append(y) predictions = np.array(predictions, dtype='int32') y = mode(predictions.T, axis=1)[0] y = np.array(y, dtype='int32') import itertools y = list(itertools.chain(*y)) assert len(y) == dataset.X.shape[0] util.write_results(y, out_path) print('Wrote predictions to submission.csv.') return np.reshape(y, (1, -1))
from pylearn2.datasets.preprocessing import Standardize, LeCunLCN, GlobalContrastNormalization from pylearn2.datasets.tfd import TFD import cPickle as pkl theano.subtensor_merge_bug=False if __name__ == "__main__": weights_file = "../out/pae_mnist_enc_weights.npy" input = T.matrix("X", dtype=theano.config.floatX) tfd_ds = TFD("unlabeled") print "TFD shape: ", tfd_ds.X.shape gcn = GlobalContrastNormalization() standardizer = Standardize() lcn = LeCunLCN(img_shape=(48, 48), channels=[0]) gcn.apply(tfd_ds, can_fit=True) standardizer.apply(tfd_ds, can_fit=True) lcn.apply(tfd_ds) rnd = numpy.random.RandomState(1231) powerup = PowerupAutoencoder(input, nvis=48*48, nhid=500, momentum=0.66, rho=0.92, num_pieces=4, cost_type="MeanSquaredCost", L2_reg=8.2*1e-5, L1_reg=1.2 * 1e-5, L1_act_reg=8.8*1e-4,
def make_majority_vote(): model_paths = ['convnet_' + str(i+1) + '.pkl' for i in range(10)] out_path = 'submission.csv' models = [] for model_path in model_paths: print('Loading ' + model_path + '...') try: with open(model_path, 'rb') as f: models.append(pkl.load(f)) except Exception as e: try: with gzip.open(model_path, 'rb') as f: models.append(pkl.load(f)) except Exception as 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) # load the test set with open('test_data_for_pylearn2.pkl', 'rb') as f: dataset = pkl.load(f) dataset = DenseDesignMatrix(X=dataset, view_converter=DefaultViewConverter(shape=[32, 32, 1], axes=['b', 0, 1, 'c'])) preprocessor = GlobalContrastNormalization(subtract_mean=True, sqrt_bias=0.0, use_std=True) preprocessor.apply(dataset) predictions = [] print('Model description:') print('') print(models[1]) print('') for model in models: model.set_batch_size(dataset.X.shape[0]) X = model.get_input_space().make_batch_theano() Y = model.fprop(X) # forward prop the test data y = T.argmax(Y, axis=1) f = function([X], y) x_arg = dataset.get_topological_view() y = f(x_arg.astype(X.dtype)) assert y.ndim == 1 assert y.shape[0] == dataset.X.shape[0] # add one to the results! y += 1 predictions.append(y) predictions = np.array(predictions, dtype='int32') y = mode(predictions.T, axis=1)[0] y = np.array(y, dtype='int32') import itertools y = list(itertools.chain(*y)) assert len(y) == dataset.X.shape[0] util.write_results(y, out_path) print('Wrote predictions to submission.csv.') return np.reshape(y, (1, -1))
from pylearn2.datasets.tfd import TFD import pickle as pkl theano.subtensor_merge_bug = False if __name__ == "__main__": weights_file = "../out/pae_mnist_enc_weights.npy" input = T.matrix("X", dtype=theano.config.floatX) tfd_ds = TFD("unlabeled") print(("TFD shape: ", tfd_ds.X.shape)) gcn = GlobalContrastNormalization() standardizer = Standardize() lcn = LeCunLCN(img_shape=(48, 48), channels=[0]) gcn.apply(tfd_ds, can_fit=True) standardizer.apply(tfd_ds, can_fit=True) lcn.apply(tfd_ds) rnd = numpy.random.RandomState(1231) powerup = PowerupAutoencoder(input, nvis=48 * 48, nhid=500, momentum=0.66, rho=0.92, num_pieces=4, cost_type="MeanSquaredCost", L2_reg=8.2 * 1e-5, L1_reg=1.2 * 1e-5, L1_act_reg=8.8 * 1e-4,