Exemple #1
0
# Autoencoder
autoencoder = AutoEncoder(784, [900, 500, 250, 2],
                          [['rbmw1', 'rbmhb1'], ['rbmw2', 'rbmhb2'],
                           ['rbmw3', 'rbmhb3'], ['rbmw4', 'rbmhb4']],
                          tied_weights=False)

iterations = len(trX) / FLAGS.batchsize

# Train First RBM
print('first rbm')
for i in range(FLAGS.epochs):
    for j in range(iterations):
        batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize)
        rbmobject1.partial_fit(batch_xs)
    print(rbmobject1.compute_cost(trX))
    show_image("out/1rbm.jpg", rbmobject1.n_w, (28, 28), (30, 30))
rbmobject1.save_weights('./out/rbmw1.chp')

# Train Second RBM2
print('second rbm')
for i in range(FLAGS.epochs):
    for j in range(iterations):
        batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize)
        # Transform features with first rbm for second rbm
        batch_xs = rbmobject1.transform(batch_xs)
        rbmobject2.partial_fit(batch_xs)
    print(rbmobject2.compute_cost(rbmobject1.transform(trX)))
    show_image("out/2rbm.jpg", rbmobject2.n_w, (30, 30), (25, 20))
rbmobject2.save_weights('./out/rbmw2.chp')
rbm1 = RBM(inputData[0].shape[0], 900, ['rbmw1', 'rbvb1', 'rbmhb1'], 0.3)
rbm2 = RBM(900, 500, ['rbmw2', 'rbvb2', 'rbmhb2'], 0.3)
rbm3 = RBM(500, 250, ['rbmw3', 'rbvb3', 'rbmhb3'], 0.3)
rbm4 = RBM(250, 2,   ['rbmw4', 'rbvb4', 'rbmhb4'], 0.3)

epoch = 1

# Train First RBM
print('first rbm')

for g in range(epoch):
    for it in range(len(inputData)):
        trX = inputData[it][np.newaxis]
        rbm1.partial_fit(trX)
        print(rbm1.compute_cost(trX))
    print(rbm1.compute_cost(trX))
    #show_image("1rbm.jpg", rbm1.n_w, (28, 28), (30, 30))
rbm1.save_weights('./rbmw1.chp')

# Train Second RBM2
print('second rbm')

for g in range(epoch):
    for it in range(len(inputData)):
        trX = inputData[it][np.newaxis]
        # Transform features with first rbm for second rbm
        trX = rbm1.transform(trX)
        rbm2.partial_fit(trX)
        print(rbm2.compute_cost(trX))
    print(rbm2.compute_cost(trX))
from rbm import RBM
from au import AutoEncoder
import tensorflow as tf
import input_data
from utilsnn import show_image, min_max_scale
import matplotlib.pyplot as plt
import numpy as np

import PreprocessGenerative as i

inputData = i.importData()

rbm1 = RBM(inputData[0].shape[0], 900, ['rbmw1', 'rbvb1', 'rbmhb1'], 0.3)

epoch = 1

# Train RBM
print('rbm')

for g in range(epoch):
    for it in range(len(inputData)):
        trX = inputData[it][np.newaxis]
        rbm1.partial_fit(trX)
        print(rbm1.compute_cost(trX))
    print(rbm1.compute_cost(trX))
rbm1.save_weights('./rbmw1.chp')

print("Training Complete")
import matplotlib.pyplot as plt
import numpy as np

import PreprocessGenerative as i


inputData = i.importData()


rbm1 = RBM(inputData[0].shape[0], 900, ['rbmw1', 'rbvb1', 'rbmhb1'], 0.3)


epoch = 1

# Train RBM
print('rbm')

for g in range(epoch):
    for it in range(len(inputData)):
        trX = inputData[it][np.newaxis]
        rbm1.partial_fit(trX)
        print(rbm1.compute_cost(trX))
    print(rbm1.compute_cost(trX))
rbm1.save_weights('./rbmw1.chp')


print("Training Complete")



Exemple #5
0
# Autoencoder
autoencoder = AutoEncoder(784, [900, 500, 250, 2], [['rbmw1', 'rbmhb1'],
                                                    ['rbmw2', 'rbmhb2'],
                                                    ['rbmw3', 'rbmhb3'],
                                                    ['rbmw4', 'rbmhb4']], tied_weights=False)

iterations = len(trX) / FLAGS.batchsize

# Train First RBM
print('first rbm')
for i in range(FLAGS.epochs):
  for j in range(iterations):
    batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize)
    rbmobject1.partial_fit(batch_xs)
  print(rbmobject1.compute_cost(trX))
  show_image("out/1rbm.jpg", rbmobject1.n_w, (28, 28), (30, 30))
rbmobject1.save_weights('./out/rbmw1.chp')

# Train Second RBM2
print('second rbm')
for i in range(FLAGS.epochs):
  for j in range(iterations):
    batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize)
    # Transform features with first rbm for second rbm
    batch_xs = rbmobject1.transform(batch_xs)
    rbmobject2.partial_fit(batch_xs)
  print(rbmobject2.compute_cost(rbmobject1.transform(trX)))
  show_image("out/2rbm.jpg", rbmobject2.n_w, (30, 30), (25, 20))
rbmobject2.save_weights('./out/rbmw2.chp')