Skip to content

Instantly share code, notes, and snippets.

@TNick
Last active August 29, 2015 14:22
Show Gist options
  • Save TNick/5bb2fba0de41a03b8b9f to your computer and use it in GitHub Desktop.
Save TNick/5bb2fba0de41a03b8b9f to your computer and use it in GitHub Desktop.
from pylearn2.utils import serial
from pylearn2.datasets.zca_dataset import ZCA_Dataset
dataset = ZCA_Dataset(
preprocessed_dataset=serial.load("${PYLEARN2_DATA_PATH}/cifar10/pylearn2_gcn_whitened/train.pkl"),
preprocessor=serial.load("${PYLEARN2_DATA_PATH}/cifar10/pylearn2_gcn_whitened/preprocessor.pkl"),
axes=['c', 0, 1, 'b']
)
from pylearn2.models.maxout import MaxoutConvC01B
h0 = MaxoutConvC01B(
layer_name='h0',
pad=4,
tied_b=1,
W_lr_scale=.05,
b_lr_scale=.05,
num_channels=96,
num_pieces=2,
kernel_shape=[8, 8],
pool_shape=[4, 4],
pool_stride=[2, 2],
irange=.005,
max_kernel_norm=.9,
partial_sum=33
)
h1 = MaxoutConvC01B(
layer_name='h1',
pad=3,
tied_b=1,
W_lr_scale=.05,
b_lr_scale=.05,
num_channels=192,
num_pieces=2,
kernel_shape=[8, 8],
pool_shape=[4, 4],
pool_stride=[2, 2],
irange=.005,
max_kernel_norm=1.9365,
partial_sum=15
)
h2 = MaxoutConvC01B(
pad=3,
layer_name='h2',
tied_b=1,
W_lr_scale=.05,
b_lr_scale=.05,
num_channels=192,
num_pieces=2,
kernel_shape=[5, 5],
pool_shape=[2, 2],
pool_stride=[2, 2],
irange=.005,
max_kernel_norm=1.9365
)
from pylearn2.models.maxout import Maxout
h3 = Maxout(
layer_name='h3',
irange=.005,
num_units=500,
num_pieces=5,
max_col_norm=1.9
)
from pylearn2.models.mlp import Softmax
y = Softmax(
max_col_norm=1.9365,
layer_name='y',
n_classes=10,
irange=.005
)
window_shape = [32, 32]
from pylearn2.space import Conv2DSpace
input_space = Conv2DSpace(
shape=window_shape,
num_channels=3,
axes=['c', 0, 1, 'b'],
)
from pylearn2.models.mlp import MLP
model = MLP(layers=[h0, h1, h2, h3, y],
input_space=input_space)
valid_dataset = ZCA_Dataset(
preprocessed_dataset=serial.load("${PYLEARN2_DATA_PATH}/cifar10/pylearn2_gcn_whitened/test.pkl"),
preprocessor=serial.load("${PYLEARN2_DATA_PATH}/cifar10/pylearn2_gcn_whitened/preprocessor.pkl"),
axes=['c', 0, 1, 'b']
)
from pylearn2.training_algorithms.sgd import SGD
from pylearn2.training_algorithms.learning_rule import Momentum
from pylearn2.termination_criteria import EpochCounter
from pylearn2.costs.mlp.dropout import Dropout
algorithm = SGD(
batch_size=128,
learning_rate=.17,
learning_rule=Momentum(init_momentum=.5),
monitoring_dataset={'test': valid_dataset},
cost=Dropout(
input_include_probs={'h0': .8},
input_scales={'h0': 1.}
),
termination_criterion=EpochCounter(max_epochs=474)
)
from pylearn2.train import Train
from pylearn2.training_algorithms.learning_rule import MomentumAdjustor
from pylearn2.training_algorithms.sgd import LinearDecayOverEpoch
from pylearn2.train_extensions.window_flip import WindowAndFlip
train_obj = Train(
dataset=dataset,
model=model,
algorithm=algorithm,
extensions=[
MomentumAdjustor(
start=1,
saturate=250,
final_momentum=.65
),
LinearDecayOverEpoch(
start=1,
saturate=500,
decay_factor=.01
),
WindowAndFlip(
pad_randomized=4,
window_shape=window_shape,
randomize=[dataset],
center=[valid_dataset]
)
],
save_path="${PYLEARN2_TRAIN_FILE_FULL_STEM}.pkl",
save_freq=1
)
train_obj.main_loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment