示例#1
0
    def __init__(self):
        self.width = 28
        self.height = 28
        self.testds, self.trainds = \
            makeMnistDataSets('/Users/bayerj/Desktop/MNIST/')
        
        # Initialize MDRNN
        self.net = _FeedForwardNetwork()
        inlayer = LinearLayer(self.width * self.height)
        hiddenlayer = MdrnnLayer(timedim=2, 
                                 shape=(self.width, self.height), 
                                 blockshape=(1, 1), 
                                 hiddendim=4,
                                 outsize=10,
                                 name='mdrnn')
        outlayer = SigmoidLayer(self.width * self.height * 10)
        con1 = IdentityConnection(inlayer, hiddenlayer)
        con2 = IdentityConnection(hiddenlayer, outlayer)
        self.net.addInputModule(inlayer)
        self.net.addModule(hiddenlayer)
        self.net.addOutputModule(outlayer)
        self.net.addConnection(con1)
        self.net.addConnection(con2)

        self.net.sortModules()
示例#2
0
文件: dbn-mnist.py 项目: HKou/pybrain
__author__ = 'Justin S Bayer, [email protected]'
__version__ = '$Id$'


import scipy

from pybrain.datasets import UnsupervisedDataSet
from pybrain.unsupervised.trainers.deepbelief import DeepBeliefTrainer
from pybrain.tools.shortcuts import buildNetwork

from pybrainexamples.datasets.mnist import makeMnistDataSets


net = buildNetwork(784, 500, 500, 2000, bias=True)
train, test = makeMnistDataSets('/Users/bayerj/Desktop/MNIST/')

trainer = DeepBeliefTrainer(net, train)
trainer.train()

print "RBM Phase finished. Now backprop."
softmaxer = SoftmaxLayer(10)
con = FullConnection(net.outmodules[0], softmaxer)
net.addModule(softmaxer)
net.outmodules = [softmaxer]

trainer = BackpropTrainer(trainer, ds)
for i in xrange(sys.maxint):
    error = trainer.train()
    print "%i: %.2f" % (i, error)