Пример #1
0
def training(autoencoder, encoder, augment, batch):
    sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9,
              nesterov=True)  # Adam(lr=0.01)
    autoencoder.compile(optimizer=sgd,
                        loss='binary_crossentropy',
                        metrics=['accuracy'])

    x_train, x_test = dataset_loader.load_data_wrapper()
    train_set, test_set, valid_set = dataset_loader.data_preprocessing(
        x_train, x_test, augment)

    early = EarlyStopping(monitor='val_loss',
                          min_delta=0,
                          patience=50,
                          mode='min',
                          verbose=1)

    autoencoder.fit(train_set[0],
                    train_set[1],
                    epochs=500,
                    batch_size=batch,
                    shuffle=True,
                    validation_data=(valid_set[0], valid_set[1]),
                    callbacks=[early])
    # TensorBoard(log_dir='C:/Users/213539359/Downloads/AlexNet-Tensorflow-master/logs/'),
    # autoencoder.save('C:/Users/213539359/Downloads/AlexNet-Tensorflow-master/model/autoencoder_3.h5')

    encoded_img = encoder.predict(test_set[0])
    decoded_imgs = autoencoder.predict(test_set[0])

    results = autoencoder.evaluate(test_set[0], test_set[1], batch_size=1)
    print("TEST LOSS, TEST ACC: ", results)

    return x_test, decoded_imgs, encoded_img
Пример #2
0
import dataset_loader
training_data, validation_data, test_data = dataset_loader.load_data_wrapper()
import neuralnet
x = int(input("Enter the no. of neurons in the hidden layer: "))
net = neuralnet.NeuralNet([784, x, 10])
e = int(input("Enter the no. of epochs: "))
s = int(input("Enter the size of each batch: "))
l = int(input("Enter the learning rate: "))
net.train(training_set=training_data,
          no_of_epochs=e,
          size_of_batch=s,
          learning_rate=l,
          test_set=test_data)