Skip to content

Commit

Permalink
Revert "remove example which is now redunant because of tutorial"
Browse files Browse the repository at this point in the history
This reverts commit 5ad2cc8.
  • Loading branch information
rizar committed Jan 19, 2015
1 parent 837a420 commit d5e58bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/mnist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

from theano import tensor

from blocks.algorithms import GradientDescent, SteepestDescent
from blocks.bricks import MLP, Tanh, Identity
from blocks.bricks.cost import CategoricalCrossEntropy
from blocks.datasets import DataStream
from blocks.datasets.mnist import MNIST
from blocks.datasets.schemes import SequentialScheme
from blocks.extensions import FinishAfter, Printing
from blocks.main_loop import MainLoop


def main():
mlp = MLP([Tanh(), Identity()], [784, 100, 10])
x = tensor.matrix('features')
y = tensor.lmatrix('targets')
cost = CategoricalCrossEntropy().apply(y.flatten() - 1, mlp.apply(x))

mnist = MNIST("train")

main_loop = MainLoop(
mlp,
DataStream(mnist,
iteration_scheme=SequentialScheme(mnist.num_examples, 20)),
GradientDescent(cost=cost,
step_rule=SteepestDescent(learning_rate=0.1)),
extensions=[FinishAfter(after_n_epochs=2),
Printing()])
main_loop.run()

if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pylearn2

import blocks
from examples.mnist import main as mnist_test
from examples.pylearn2.markov_chain import main as pylearn2_test


Expand All @@ -17,6 +18,12 @@ def setup():
logger.setLevel(logging.ERROR)


def test_mnist():
mnist_test()

test_mnist.setup = setup


def test_pylearn2():
filename = 'unittest_markov_chain'
pylearn2_test('train', filename, 0, 3, False)
Expand Down

0 comments on commit d5e58bb

Please sign in to comment.