def test_mnist(): """ Test the mnist.yaml file from the maxout paper on random input """ skip_if_no_gpu() train = load_train_file( os.path.join(pylearn2.__path__[0], "scripts/papers/maxout/mnist.yaml")) # Load fake MNIST data init_value = control.load_data control.load_data = [False] train.dataset = MNIST(which_set='train', one_hot=1, axes=['c', 0, 1, 'b'], start=0, stop=100) train.algorithm._set_monitoring_dataset(train.dataset) control.load_data = init_value # Train shortly and prevent saving train.algorithm.termination_criterion = EpochCounter(max_epochs=1) train.extensions.pop(0) train.save_freq = 0 train.main_loop()
def setUp(self): """ Set up a test image and filter to re-use """ skip_if_no_gpu() self.image = \ numpy.random.rand(16, 3, 3, 1).astype(theano.config.floatX) self.image_tensor = tensor.tensor4() self.filters_values = numpy.ones((2, 2, 16, 2, 2, 1, 16), dtype=theano.config.floatX) self.filters = sharedX(self.filters_values, name='filters') self.local = Local(self.filters, (3, 3), 1)
def setUp(self): """ Set up a test image and filter to re-use """ skip_if_no_gpu() self.image = \ numpy.random.rand(16, 3, 3, 1).astype(theano.config.floatX) self.image_tensor = tensor.tensor4() self.filters_values = numpy.ones( (2, 2, 16, 2, 2, 1, 16), dtype=theano.config.floatX ) self.filters = sharedX(self.filters_values, name='filters') self.local = Local(self.filters, (3, 3), 1)
def setUp(self): """ Set up a test image and filter to re-use. """ skip_if_no_gpu() if not dnn_available(): raise SkipTest('Skipping tests cause cudnn is not available') self.orig_floatX = theano.config.floatX theano.config.floatX = 'float32' self.image = np.random.rand(1, 1, 3, 3).astype(theano.config.floatX) self.image_tensor = tensor.tensor4() self.input_space = Conv2DSpace((3, 3), 1, axes=('b', 'c', 0, 1)) self.filters_values = np.ones((1, 1, 2, 2), dtype=theano.config.floatX) self.filters = sharedX(self.filters_values, name='filters') self.batch_size = 1 self.cudnn2d = Cudnn2D(self.filters, self.batch_size, self.input_space)
def setUp(self): """ Set up a test image and filter to re-use. """ skip_if_no_gpu() if not dnn_available(): raise SkipTest('Skipping tests cause cudnn is not available') self.orig_floatX = theano.config.floatX theano.config.floatX = 'float32' self.image = np.random.rand(1, 1, 3, 3).astype(theano.config.floatX) self.image_tensor = tensor.tensor4() self.input_space = Conv2DSpace((3, 3), 1, axes=('b', 'c', 0, 1)) self.filters_values = np.ones( (1, 1, 2, 2), dtype=theano.config.floatX ) self.filters = sharedX(self.filters_values, name='filters') self.batch_size = 1 self.cudnn2d = Cudnn2D(self.filters, self.batch_size, self.input_space)
def test_mnist(): """ Test the mnist.yaml file from the maxout paper on random input """ skip_if_no_gpu() train = load_train_file(os.path.join(pylearn2.__path__[0], "scripts/papers/maxout/mnist.yaml")) # Load fake MNIST data init_value = control.load_data control.load_data = [False] train.dataset = MNIST(which_set='train', one_hot=1, axes=['c', 0, 1, 'b'], start=0, stop=100) train.algorithm._set_monitoring_dataset(train.dataset) control.load_data = init_value # Train shortly and prevent saving train.algorithm.termination_criterion = EpochCounter(max_epochs=1) train.extensions.pop(0) train.save_freq = 0 train.main_loop()
__authors__ = "David Warde-Farley, Ian Goodfellow" __copyright__ = "Copyright 2010-2012, Universite de Montreal" __credits__ = ["David Warde-Farley", "Ian Goodfellow"] __license__ = "3-clause BSD" __maintainer__ = "David Warde-Farley" __email__ = "wardefar@iro" from pylearn2.testing.skip import skip_if_no_gpu skip_if_no_gpu() import numpy as np import warnings from theano import function from theano.sandbox.cuda import gpu_from_host from theano.sandbox.cuda import host_from_gpu from theano.sandbox.rng_mrg import MRG_RandomStreams from theano import shared from theano import tensor as T from theano.tensor import as_tensor_variable from theano.tensor.nnet.conv import conv2d from pylearn2.sandbox.cuda_convnet.img_acts import ImageActs def test_match_full_conv(): # Tests that running ImageActs with no padding is the same as running # theano's conv2D in full mode after flipping the kernel and tranposing # the output and input channels # In other words, if convolution computes H=XK, we now compute # R=HK^T
__authors__ = "David Warde-Farley, Ian Goodfellow" __copyright__ = "Copyright 2010-2012, Universite de Montreal" __credits__ = ["David Warde-Farley", "Ian Goodfellow"] __license__ = "3-clause BSD" __maintainer__ = "David Warde-Farley" __email__ = "wardefar@iro" from pylearn2.testing.skip import skip_if_no_gpu skip_if_no_gpu() import numpy as np import warnings from theano import function from theano.sandbox.cuda import gpu_from_host from theano.sandbox.cuda import host_from_gpu from theano.sandbox.rng_mrg import MRG_RandomStreams from theano import shared from theano import tensor as T from theano.tensor import as_tensor_variable from theano.tensor.nnet.conv import conv2d from pylearn2.sandbox.cuda_convnet.img_acts import ImageActs def test_match_full_conv(): # Tests that running ImageActs with no padding is the same as running # theano's conv2D in full mode after flipping the kernel and tranposing # the output and input channels # In other words, if convolution computes H=XK, we now compute
def test_biglayer(): """Test a crash during Theano compilation. It would be too long to redo this test without depending on Pylearn2. So we put it here. """ skip_if_no_gpu() yaml_string = """ !obj:pylearn2.train.Train { dataset: &train !obj:pylearn2.testing.datasets.random_one_hot_topological_dense_design_matrix { rng: !obj:numpy.random.RandomState { seed: [2014, 6, 6] }, shape: &input_shape [%(xsize)i, %(ysize)i], channels: 4, axes: ['c', 0, 1, 'b'], num_examples: 128, num_classes: 10 }, model: !obj:pylearn2.models.mlp.MLP { batch_size: 128, layers: [ !obj:pylearn2.models.mlp.FlattenerLayer { raw_layer: !obj:pylearn2.models.mlp.CompositeLayer { layer_name: 'h0', layers: [ !obj:pylearn2.models.mlp.MLP { layer_name: 'h1', layers: [ !obj:pylearn2.models.maxout.MaxoutConvC01B { layer_name: 'conv00', tied_b: 1, W_lr_scale: .05, b_lr_scale: .05, num_channels: 16, num_pieces: 1, kernel_shape: [1, 1], pool_shape: [4, 4], pool_stride: [4, 4], irange: .005, max_kernel_norm: 0.9, } ]}, !obj:pylearn2.models.maxout.Maxout { layer_name: 'max0', W_lr_scale: .1, b_lr_scale: .1, num_units: 16, irange: .005, max_col_norm: 1.9365, num_pieces: 1, } ] } }, !obj:pylearn2.models.mlp.Softmax { max_col_norm: 1.9365, layer_name: 'y', n_classes: 10, irange: .005 } ], input_space: !obj:pylearn2.space.Conv2DSpace { shape: *input_shape, num_channels: 4, axes: ['c', 0, 1, 'b'], }, }, algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { learning_rate: .05, learning_rule: !obj:pylearn2.training_algorithms.learning_rule.Momentum { init_momentum: 0.5, }, monitoring_dataset: { 'train': *train }, termination_criterion: !obj:pylearn2.termination_criteria.EpochCounter { max_epochs: 3 }, }, extensions: [ !obj:pylearn2.training_algorithms.learning_rule.MomentumAdjustor { start: 1, saturate: 250, final_momentum: .7 } ] } """ try: orig_floatX = theano.config.floatX theano.config.floatX = 'float32' theano.sandbox.cuda.use('gpu') x_size, y_size = 4, 4 parameters = {'xsize': x_size, 'ysize': y_size} test = yaml_parse.load(yaml_string % parameters) test.main_loop() finally: theano.config.floatX = orig_floatX theano.sandbox.cuda.unuse()