Example #1
0
def train(network_architecture, learning_rate= input('Enter the learning rate (default: 0.01 ~ 0.001): '),
#learning_rate = 0,001
          batch_size=100, training_epochs=70, display_step=1): #display_step=5):
    vae = VariationalAutoencoder(network_architecture,
                                 learning_rate=learning_rate,
                                 batch_size=batch_size)

    begin = time.time()
    # Training cycle
    tempo_total=0.0
    for epoch in range(training_epochs):

        avg_cost = 0.
        total_batch = int(n_samples / batch_size)


        for i in range(total_batch):   
            n = i
            batch_xs = importer_.train(batch_size, data1, n)
           

            cost = vae.partial_fit(batch_xs)

            #print cost            # Compute average loss
            avg_cost += cost / n_samples * batch_size
            #print avg_cost
        # Display logs per epoch step
        if epoch % display_step == 0:
            end = time.time()
            print ("Epoch:", '%04d' % (epoch+1), \
                  "cost=", "{:.9f}".format(avg_cost),\
                   " time = %.2fs" % (end - begin))
            tempo = (end - begin)
            tempo_total = tempo_total + tempo
            begin = end
    print "tempo total: %.2fs" % tempo_total
    reconstructed = vae.reconstruct(batch_xs)
    print reconstructed.shape
    return vae
Example #2
0
         n_hidden_recog_2=200, #500
         n_hidden_recog_3=30, #27

         n_hidden_gener_1=800,
         n_hidden_gener_2=200,
         n_hidden_gener_3=30,

         n_input= num_pix, 
         n_z=2)

print network_architecture


vae = train(network_architecture, training_epochs = num_epoch, batch_size=num_batch) #75

x_sample = importer_.train(num_batch, data1, 1)

x_reconstruct = vae.reconstruct(x_sample)


def plot_line(num_line):
    plt.figure(figsize=(15, 25))

    data1 = importer_.plot_linha((x_sample), num_line)
    data2 = importer_.plot_linha((x_reconstruct), num_line)

    x = np.array(range(len(data1)))

    plt.plot( x, data1, 'go') # green bolinha
    plt.plot( x, data1, 'k:', color='orange') # linha pontilha orange
    plt.plot( x, data2, 'ro') # red triangulo