Exemplo n.º 1
0
import numpy as np
import theano
import theano.tensor as T

import mnist_parse

# parameters
N = 50000
valN = 10000
lr = 3
epochs = 1000

# import data
rawX = mnist_parse.getImages()[:N]
rawY = mnist_parse.getLabels()[:N]
rawValX = mnist_parse.getImages()[N:N + valN]
rawValY = mnist_parse.getLabels()[N:N + valN]


# wrangle data
def x_wrangle(x_in):
    x = x_in.reshape(x_in.shape[0], x_in.shape[1] * x_in.shape[2])
    x = np.concatenate((x, np.ones((x.shape[0], 1))), axis=1)
    x -= x.mean(axis=1)[:, np.newaxis]
    x /= x.std(axis=1)[:, np.newaxis]
    return x


trainX = x_wrangle(rawX)
valX = x_wrangle(rawValX)
feats = trainX.shape[1]
Exemplo n.º 2
0
        # compile
        train_D = theano.function(inputs=[self.x,self.concat_indx],
                outputs=[self.loss_D],
                updates=[(self.D.w0, self.D.w0 - lr*self.gw0D),
                    (self.D.w1, self.D.w1 - lr*self.gw1D)])
        train_G = theano.function(inputs=[self.x,self.concat_indx],
                outputs=[self.loss_G],
                updates=[(self.G.w0, self.G.w0 - lr*self.gw0G),
                    (self.G.w1, self.G.w1 - lr*self.gw1G)])

N = 1000
noise_feats = 100
hiddens_G = 300
hiddens_D = 300
rawX = mnist_parse.getImages()[:N]

# wrangle data
def x_wrangle(x_in):
    x = x_in.reshape(x_in.shape[0], x_in.shape[1]*x_in.shape[2])
    x = np.concatenate((x, np.ones((x.shape[0],1))), axis=1)
    #x -= x.mean(axis=1)[:, np.newaxis]
    #x /= x.std(axis=1)[:, np.newaxis]
    return x
trainX = x_wrangle(rawX)
feats = trainX.shape[1]

# create GAN
gan = GAN(noise_feats, hiddens_G, feats, hiddens_D, N, N)

#feats = 10
Exemplo n.º 3
0
import mnist_parse

# parameters
n_train = 50000
classes = 10
batch_size = 100
noise_size = 100
dropout_rate = 0.25

# optimizers
g_opt = ko.Adam(lr=1e-4)
d_opt = ko.Adam(lr=1e-3)

# load images
rawX = mnist_parse.getImages().astype('float')
def x_wrangle(x_in):
    x = x_in / 255
    x = x.reshape(x.shape[0], 1, x.shape[1], x.shape[2])
    return x
wrangledX = x_wrangle(rawX)
trainX = wrangledX[:n_train]
_, _, img_rows, img_cols = trainX.shape

# noise input
def gen_noise(batch_size, d):
    return np.random.uniform(0, 1, size=[batch_size, d])

# generator
n_channels = 200
l_width = img_rows / 2