Beispiel #1
0
import numpy as np

d = DBN([28 * 28, 500, 500, 2000], 10, 0.1)
images = MNIST.load_images("images")
labels = MNIST.load_labels("labels")

img = images[0:60000]
lbl = labels[0:60000]

tst_img = MNIST.load_images("test_images")
tst_lbl = MNIST.load_labels("test_labels")

d.pre_train(img, 5, 50)
for i in xrange(0, 100):
    d.train_labels(img, lbl, 50, 50)
    tst_class = d.classify(tst_img, 10)
    print "Error over test data: {0}".format(1 - (tst_class * tst_lbl).mean() * 10)

# print d.sample(img[0:1],0)
# print d.sample(img[1:2],0)
# print 'layer 2'
# print d.sample(img[0:1],1)
# print d.sample(img[1:2],2)
# print 'layer 2'
# print d.sample(img[0:1],2)
# print d.sample(img[1:2],2)
# print 'layer 3'
# print d.sample(img[0:1],3)[0]
# print d.sample(img[1:2],3)[0]
# print 'labels'
print np.around(d.classify(img, 20), 2)[0:20]
Beispiel #2
0
images = MNIST.load_images('images')
labels = MNIST.load_labels('labels')

# Gets the training set of images
img = images[0:60000]
lbl = labels[0:60000]

# Loads the test images from the MNIST database
tst_img = MNIST.load_images('test_images')
tst_lbl = MNIST.load_labels('test_labels')

# Pre trains the DBN
d.pre_train(img,5,50)

# Executes a 100 iterations of label training
# Attempts to classify and prints the error rate
for i in xrange(0, 100):
  d.train_labels(img, lbl, 50, 50)
  tst_class = d.classify(tst_img,10)
  print 'Error over test data: {0}'.format(1 - (tst_class*tst_lbl).mean() * dbn.number_labels)


# Tests the DBN on test images
tst_class = d.classify(tst_img,20)
# Calculates the error
err_test = 1 - ((tst_class * tst_lbl).mean() * 10)

# Prints the error rate
print err_test

Beispiel #3
0
img = images[0:60000]
lbl = labels[0:60000]

# Permutes the data to ensure random batches
train_tuples = zip(img, lbl)
train_tuples = np.random.permutation(train_tuples)
(img, lbl) = zip(*train_tuples)

# Loads the test images from the MNIST database
tst_img = MNIST.load_images('test_images')
tst_lbl = MNIST.load_labels('test_labels')

# Pre trains the DBN
d.pre_train(img, 5, 50)

# Executes a 100 iterations of label training
# Attempts to classify and prints the error rate
for i in xrange(0, 100):
    d.train_labels(img, lbl, 50, 50)
    tst_class = d.classify(tst_img, 10)
    print 'Error over test data: {0}'.format(1 - (tst_class * tst_lbl).mean() *
                                             dbn.number_labels)

# Tests the DBN on test images
tst_class = d.classify(tst_img, 20)
# Calculates the error
err_test = 1 - ((tst_class * tst_lbl).mean() * 10)

# Prints the error rate
print err_test