1 | #!/usr/bin/env python |
||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | """ |
||
5 | An auto-encoder for compress MNIST images. |
||
6 | """ |
||
7 | |||
8 | |||
9 | import logging, os |
||
10 | logging.basicConfig(level=logging.INFO) |
||
11 | |||
12 | from deepy.dataset import MnistDataset, MiniBatches |
||
13 | from deepy.networks import AutoEncoder |
||
14 | from deepy.layers import Dense |
||
15 | from deepy.trainers import SGDTrainer, LearningRateAnnealer |
||
16 | from deepy.utils import shared_scalar |
||
17 | |||
18 | model_path = os.path.join(os.path.dirname(__file__), "models", "mnist_autoencoder.gz") |
||
19 | |||
20 | View Code Duplication | if __name__ == '__main__': |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
21 | model = AutoEncoder(input_dim=28 * 28, rep_dim=30) |
||
22 | model.stack_encoders(Dense(50, 'tanh'), Dense(30)) |
||
23 | model.stack_decoders(Dense(50, 'tanh'), Dense(28 * 28)) |
||
24 | |||
25 | trainer = SGDTrainer(model, {'learning_rate': shared_scalar(0.05), 'gradient_clipping': 3}) |
||
26 | |||
27 | mnist = MiniBatches(MnistDataset(for_autoencoder=True), batch_size=20) |
||
28 | |||
29 | trainer.run(mnist, controllers=[LearningRateAnnealer()]) |
||
30 | |||
31 | model.save_params(model_path) |