Esempio n. 1
0
#  format of data
# disitstrain.txt contains 3000 lines, each line 785 numbers, comma delimited

full_path = os.path.realpath(__file__)
path, filename = os.path.split(full_path)
data_filepath = '../data'
data_train_filename = 'digitstrain.txt'
data_valid_filename = 'digitsvalid.txt'
data_test_filename = 'digitstest.txt'

data_train_filepath = os.path.join(path, data_filepath, data_train_filename)
data_valid_filepath = os.path.join(path, data_filepath, data_valid_filename)
data_test_filepath = os.path.join(path, data_filepath, data_test_filename)

print('start initializing...')
numpy.random.seed(1099)

x_train, _ = load_data.load_from_path(data_train_filepath)
x_valid, _ = load_data.load_from_path(data_valid_filepath)

myAE = autoencoder.AutoEncoder(28 * 28, hidden_units=100)
myAE.set_visualize(28, 28)
myAE.set_autostop(window=40, stride=20)
myAE.train(x_train,
           x_valid,
           k=1,
           epoch=3000,
           learning_rate=0.03,
           batch_size=128,
           plotfile='script-2-5-AE')
Esempio n. 2
0
data_train_filename = 'digitstrain.txt'
data_valid_filename = 'digitsvalid.txt'
data_test_filename = 'digitstest.txt'

data_train_filepath = os.path.join(path, data_filepath, data_train_filename)
data_valid_filepath = os.path.join(path, data_filepath, data_valid_filename)
data_test_filepath = os.path.join(path, data_filepath, data_test_filename)

print('start initializing...')
network.init_nn(random_seed=1099)

learning_rates = [0.02]
momentums = [0.9]

regularizers = [0.00001]
x_train, y_train = load_data.load_from_path(data_train_filepath)
x_valid, y_valid = load_data.load_from_path(data_valid_filepath)

for i2 in range(len(regularizers)):
    for i3 in range(len(momentums)):
        for i4 in range(len(learning_rates)):
            layers = [layer.Linear(784, 100),
                      layer.BN(100, 100),
                      layer.Sigmoid(100, 100),
                      layer.Linear(100, 100),
                      layer.BN(100, 100),
                      layer.Sigmoid(100, 100),
                      layer.SoftmaxLayer(100, 10)]
            name = 'network2' + '-' + str(i2) + '-' + str(i3) + '-' + str(i4) + '.dump'
            myNN = NN(layers, learning_rate=learning_rates[i4], regularizer=regularizers[i2], momentum=momentums[i3])
            myNN.train(x_train, y_train, x_valid, y_valid, epoch=300, batch_size=32)