Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
Updating the MNIST benchmarking to compare nolearn and lasagne.
Browse files Browse the repository at this point in the history
  • Loading branch information
Team AiGameDev.com committed Apr 10, 2015
1 parent 7ee312c commit 1a61c7d
Showing 1 changed file with 55 additions and 26 deletions.
81 changes: 55 additions & 26 deletions examples/bench_mnist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from sklearn.cross_validation import train_test_split
from sklearn.datasets import fetch_mldata
import logging

import sys
import time
import logging
import numpy as np

np.set_printoptions(precision=4)
Expand All @@ -21,52 +23,79 @@
classifiers = []


try:
from nolearn.dbn import DBN
clf = DBN(
[X_train.shape[1], 300, 10],
learn_rates=0.3,
learn_rate_decays=0.9,
epochs=10,
verbose=1)
classifiers.append(('nolearn.dbn', clf))
except ImportError:
pass


# try:
# raise ImportError
#
# from nolearn.dbn import DBN
# clf = DBN(
# [X_train.shape[1], 300, 10],
# learn_rates=0.3,
# learn_rate_decays=0.9,
# epochs=10,
# verbose=1)
# classifiers.append(('nolearn.dbn', clf))
# except ImportError:
# pass
try:
from nolearn.lasagne import NeuralNet
from lasagne.layers import InputLayer, DenseLayer
from lasagne.nonlinearities import softmax
from lasagne.updates import nesterov_momentum

clf = NeuralNet(
layers=[
('input', InputLayer),
('hidden1', DenseLayer),
('output', DenseLayer),
],
input_shape=(None, 784),
output_num_units=10,
output_nonlinearity=softmax,
eval_size=0.0,

more_params=dict(
hidden1_num_units=300,
),

update=nesterov_momentum,
update_learning_rate=0.02,
update_momentum=0.9,

max_epochs=10,
verbose=1
)
classifiers.append(('nolearn.lasagne', clf))

except ImportError:
pass


try:
from sknn.mlp import MultiLayerPerceptronClassifier

clf = MultiLayerPerceptronClassifier(
layers=[("Maxout", 50, 2),("Maxout", 50, 2), ("Softmax",)],
learning_rate=0.01,
batch_size=10,
n_stable=50,
f_stable=0.0,
n_iter=2,
layers=[("Rectifier", 300), ("Softmax",)],
learning_rate=0.02,
learning_rule='momentum',
# dropout=True,
verbose=1,
batch_size=25,
n_stable=10,
n_iter=10,
verbose=0,
)
classifiers.append(('sknn.mlp', clf))
except ImportError:
pass


for name, clf in classifiers:
print y_train

clf.fit(X_train, y_train)
start = time.time()
clf.fit(X_train.astype(np.float32), y_train.astype(np.int32))

from sklearn.metrics import classification_report

y_pred = clf.predict(X_test)
print name
#exit()
print "\tAccuracy:", clf.score(X_test, y_test)
print "\tTime:", time.time() - start
print "\tReport:"
print classification_report(y_test, y_pred)

0 comments on commit 1a61c7d

Please sign in to comment.