示例#1
0
def get_maxout(dim_input):
    config = {
        'batch_size':
        bsize,
        'input_space':
        Conv2DSpace(shape=dim_input[:2],
                    num_channels=dim_input[2],
                    axes=['c', 0, 1, 'b']),
        'layers': [
            MaxoutConvC01B(layer_name='h0',
                           num_channels=96,
                           num_pieces=2,
                           irange=.005,
                           tied_b=1,
                           max_kernel_norm=.9,
                           kernel_shape=[8, 8],
                           pool_shape=[4, 4],
                           pool_stride=[2, 2],
                           W_lr_scale=.05,
                           b_lr_scale=.05),
            MaxoutConvC01B(layer_name='h1',
                           num_channels=128,
                           num_pieces=2,
                           irange=.005,
                           tied_b=1,
                           max_kernel_norm=0.9,
                           kernel_shape=[7, 7],
                           pad=3,
                           pool_shape=[4, 4],
                           pool_stride=[2, 2],
                           W_lr_scale=.05,
                           b_lr_scale=.05),
            MaxoutConvC01B(layer_name='h2',
                           num_channels=160,
                           num_pieces=3,
                           irange=.005,
                           tied_b=1,
                           max_kernel_norm=0.9,
                           kernel_shape=[6, 6],
                           pad=2,
                           pool_shape=[2, 2],
                           pool_stride=[2, 2],
                           W_lr_scale=.05,
                           b_lr_scale=.05),
            MaxoutConvC01B(layer_name='h3',
                           num_channels=192,
                           num_pieces=4,
                           irange=.005,
                           tied_b=1,
                           max_kernel_norm=0.9,
                           kernel_shape=[5, 5],
                           pad=1,
                           pool_shape=[2, 2],
                           pool_stride=[2, 2],
                           W_lr_scale=.05,
                           b_lr_scale=.05),
            Maxout(layer_name='h4',
                   irange=.005,
                   num_units=500,
                   num_pieces=5,
                   max_col_norm=1.9),
            Softmax(layer_name='y',
                    n_classes=nclass,
                    irange=.005,
                    max_col_norm=1.9)
        ]
    }
    return MLP(**config)
示例#2
0
def generateConvRegressor(teacher_hintlayer, student_layer):
  
  layer_name = 'hint_regressor'
  out_ch = teacher_hintlayer.get_output_space().num_channels
  ks0 = student_layer.get_output_space().shape[0] - teacher_hintlayer.get_output_space().shape[0] + 1
  ks1 = student_layer.get_output_space().shape[1] - teacher_hintlayer.get_output_space().shape[1] + 1
  ks = [ks0, ks1]
  irng = 0.05
  mkn = 0.9
  tb = 1  
        
  if isinstance(teacher_hintlayer, MaxoutConvC01B):
    hint_reg_layer = MaxoutConvC01B(num_channels=out_ch, 
				    num_pieces=teacher_hintlayer.num_pieces, 
				    kernel_shape=ks, 
				    pool_shape=[1,1], 
				    pool_stride=[1,1], 
				    layer_name=layer_name, 
				    irange=irng,  
				    max_kernel_norm=mkn, 
				    tied_b=teacher_hintlayer.tied_b)

  elif isinstance(teacher_hintlayer, ConvRectifiedLinear):
    nonlin = RectifierConvNonlinearity()
    hint_reg_layer = ConvElemwise(output_channels = out_ch,
				  kernel_shape = ks,
				  layer_name = layer_name,
				  nonlinearity = nonlin,
				  irange = irng,
				  max_kernel_norm = mkn,
				  tied_b = tb)
				  
  elif isinstance(teacher_hintlayer, ConvElemwise):
    nonlin = teacher_hintlayer.nonlinearity
    
    #if isinstance(nonlin,TanhConvNonlinearity):
    #  nonlin = SigmoidConvNonlinearity()
      
    hint_reg_layer = ConvElemwise(output_channels = out_ch,
				  kernel_shape = ks,
				  layer_name = layer_name,
				  nonlinearity = nonlin,
				  irange = irng,
				  max_kernel_norm = mkn,
				  tied_b = tb)   
  elif isinstance(teacher_hintlayer, ConvElemwisePL2):
    nonlin = teacher_hintlayer.nonlinearity
    
    #if isinstance(nonlin,TanhConvNonlinearity):
    #  nonlin = SigmoidConvNonlinearity()
      
    hint_reg_layer = ConvElemwisePL2(output_channels = out_ch,
				  kernel_shape = ks,
				  layer_name = layer_name,
				  nonlinearity = nonlin,
				  irange = irng,
				  max_kernel_norm = mkn,
				  tied_b = tb) 
  elif isinstance(teacher_hintlayer, CudNNElemwise):
    nonlin = teacher_hintlayer.nonlinearity
    
    #if isinstance(nonlin,TanhConvNonlinearity):
    #  nonlin = SigmoidConvNonlinearity()
      
    hint_reg_layer = CudNNElemwise(output_channels = out_ch,
				  kernel_shape = ks,
				  layer_name = layer_name,
				  nonlinearity = nonlin,
				  irange = irng,
				  max_kernel_norm = mkn,
				  tied_b = tb) 
  else:
    raise AssertionError("Unknown layer type")
    
  return hint_reg_layer
示例#3
0
    MonitorBasedSaveBest(channel_name='valid_y_misclass',
                         save_path=save_best_path),
    MomentumAdjustor(start=1, saturate=250, final_momentum=.7)
]

model = MLP(batch_size=batch_size,
            input_space=Conv2DSpace(shape=[48, 48],
                                    num_channels=num_chan,
                                    axes=['c', 0, 1, 'b']),
            layers=[
                MaxoutConvC01B(layer_name='h0',
                               pad=0,
                               num_channels=64,
                               num_pieces=2,
                               kernel_shape=[8, 8],
                               pool_shape=[4, 4],
                               pool_stride=[2, 2],
                               irange=.005,
                               max_kernel_norm=.9,
                               W_lr_scale=0.5,
                               b_lr_scale=0.5),
                MaxoutConvC01B(layer_name='h1',
                               pad=0,
                               num_channels=64,
                               num_pieces=2,
                               kernel_shape=[8, 8],
                               pool_shape=[3, 3],
                               pool_stride=[2, 2],
                               irange=.005,
                               max_kernel_norm=.9,
                               W_lr_scale=0.5,
示例#4
0
translation = 9.
center_shape = (img_dim - 2, img_dim - 2)
preprocess = [
    preprocessing.GlobalContrastNormalization(sqrt_bias=10., use_std=True),
    preprocessing.LeCunLCN([img_dim, img_dim], batch_size=5000)
]

#number of random test augmentations to predict
test_examples = 2

#convolutional layers
l1 = MaxoutConvC01B(layer_name='l1',
                    tied_b=1,
                    num_channels=32,
                    num_pieces=2,
                    pad=0,
                    kernel_shape=[4, 4],
                    pool_shape=[2, 2],
                    pool_stride=[2, 2],
                    max_kernel_norm=1.9365,
                    irange=.025)
l2 = MaxoutConvC01B(layer_name='l2',
                    tied_b=1,
                    num_channels=64,
                    num_pieces=2,
                    pad=3,
                    kernel_shape=[4, 4],
                    pool_shape=[2, 2],
                    pool_stride=[2, 2],
                    max_kernel_norm=1.9365,
                    irange=.025)
l3 = MaxoutConvC01B(layer_name='l3',
示例#5
0
import theano
from adversarial.deconv import Deconv
from pylearn2.datasets.mnist import MNIST
from pylearn2.space import Conv2DSpace
from pylearn2.models.mlp import MLP
from pylearn2.models.maxout import MaxoutConvC01B
from pylearn2.gui import patch_viewer
import ipdb


input_space = Conv2DSpace(shape = (28, 28), num_channels=1, axes = ('c', 0, 1, 'b'))
conv = MaxoutConvC01B(layer_name = 'conv',
                        num_channels = 16,
                        num_pieces = 1,
                        kernel_shape = (4, 4),
                        pool_shape = (1, 1),
                        pool_stride=(1, 1),
                        irange = 0.05)
deconv = Deconv(layer_name = 'deconv',
                num_channels = 1,
                kernel_shape = (4, 4),
                irange = 0.05)

mlp = MLP(input_space =input_space,
        layers = [conv, deconv])

mlp.layers[1].transformer._filters.set_value(mlp.layers[0].transformer._filters.get_value())

x = input_space.get_theano_batch()
out = mlp.fprop(x)