Created
September 10, 2014 19:19
-
-
Save cancan101/bc906a567c26c565e477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ['THEANO_FLAGS']="optimizer_including=conv_fft_valid:conv_fft_full" | |
from pylearn2.config import yaml_parse | |
from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix | |
import numpy as np | |
train_str = """!obj:pylearn2.train.Train { | |
dataset: &train !import '__main__ .train_set', | |
model: null, | |
algorithm: !obj:pylearn2.training_algorithms.sgd.SGD { | |
batch_size: 6, | |
learning_rate: .005, | |
learning_rule: !obj:pylearn2.training_algorithms.learning_rule.Momentum { | |
init_momentum: 0.15 | |
}, | |
cost: !obj:pylearn2.costs.mlp.dropout.Dropout { | |
input_include_probs: { 'h0' : 0.8, }, | |
input_scales: { 'h0' : 1.25,} | |
}, | |
monitor_iteration_mode : "even_shuffled_sequential", | |
train_iteration_mode : "even_shuffled_sequential", | |
monitoring_dataset: { | |
'valid' : !import '__main__ .valid' | |
}, | |
termination_criterion: !obj:pylearn2.termination_criteria.And { | |
criteria: [ | |
!obj:pylearn2.termination_criteria.MonitorBased { | |
channel_name: "valid_y_misclass", | |
prop_decrease: 0.01, | |
N: 30 | |
}, | |
!obj:pylearn2.termination_criteria.EpochCounter { | |
max_epochs: 50 | |
}, | |
] | |
}, | |
}, | |
extensions: [ | |
!obj:pylearn2.training_algorithms.learning_rule.MomentumAdjustor { | |
start: 1, | |
saturate: 40, | |
final_momentum: 0.60 | |
}, | |
!obj:pylearn2.training_algorithms.sgd.LinearDecayOverEpoch { | |
start: 20, | |
saturate: 100, | |
decay_factor: 0.1 | |
}, | |
] | |
}""" | |
y_labels = 4 | |
labels = [0] * 100 | |
y = np.array(labels)[:,np.newaxis] | |
y[0] = 1 | |
y[0] = 2 | |
y[0] = 3 | |
train_set = DenseDesignMatrix(topo_view=np.zeros((100,300,400,1)), y=y, y_labels=y_labels) | |
valid = DenseDesignMatrix(topo_view=np.zeros((100,300,400,1)), y=y, y_labels=y_labels) | |
train = yaml_parse.load(train_str) | |
model_str = """ | |
!obj:pylearn2.models.mlp.MLP { | |
input_space: !obj:pylearn2.space.Conv2DSpace { | |
shape: [300, 400], | |
num_channels: 1 | |
}, | |
layers: [ !obj:pylearn2.models.mlp.ConvRectifiedLinear { | |
layer_name: 'h0', | |
output_channels: 32, | |
irange: .05, | |
kernel_shape: [11, 11], | |
pool_shape: [4, 4], | |
pool_stride: [2, 2], | |
max_kernel_norm: 1.9365, | |
detector_normalization: !obj:pylearn2.expr.normalize.CrossChannelNormalization {}, | |
}, !obj:pylearn2.models.mlp.ConvRectifiedLinear { | |
layer_name: 'h1', | |
output_channels: 32, | |
irange: .05, | |
kernel_shape: [5, 5], | |
pool_shape: [4, 4], | |
pool_stride: [3, 3], | |
max_kernel_norm: 1.9365, | |
detector_normalization: !obj:pylearn2.expr.normalize.CrossChannelNormalization {}, | |
}, !obj:pylearn2.models.mlp.ConvRectifiedLinear { | |
layer_name: 'h2', | |
output_channels: 32, | |
irange: .05, | |
kernel_shape: [3, 3], | |
pool_shape: [5, 5], | |
pool_stride: [5, 5], | |
max_kernel_norm: 1.9365, | |
detector_normalization: !obj:pylearn2.expr.normalize.CrossChannelNormalization {}, | |
}, !obj:pylearn2.models.maxout.Maxout { | |
layer_name: 'h3', | |
num_units: 100, | |
num_pieces: 2, | |
irange: 0.0575059125935, | |
max_col_norm: 12., | |
}, !obj:pylearn2.models.mlp.Softmax { | |
max_col_norm: 3.9365, | |
layer_name: 'y', | |
n_classes: 4, | |
irange: 0.005000 | |
} | |
], | |
} | |
""" | |
model = yaml_parse.load(model_str) | |
train.model = model | |
train.main_loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment