def main(epochs=20): Nin = 784 Nh_l = [100, 50] number_of_class = 10 Nout = number_of_class data = Data_func() model = DNN(Nin, Nh_l, Nout) batch_size = 100 (X_train, Y_train), (X_test, Y_test) = data N_tr = X_train.shape[0] loss_l = {"loss": [], "val_loss": []} acc_l = {"accuracy": [], "val_accuracy": []} for epoch in range(epochs): # Train train(model, X_train, Y_train, N_tr, batch_size) # Validation validation(model, X_test, Y_test) print(f'Epoch {epoch}, ' f'Loss: {tr_loss.result():.3}, ' f'Acc: {tr_acc.result() * 100:.3}, ' f'Test Loss: {te_loss.result():.3}, ' f'Test Accuracy: {te_acc.result() * 100:.3}') loss_l["loss"].append(tr_loss.result()) acc_l["accuracy"].append(tr_acc.result()) loss_l["val_loss"].append(te_loss.result()) acc_l["val_accuracy"].append(te_acc.result()) plot_loss(loss_l) plot_acc(acc_l) plt.show()
def main(): model = DNN(Nin, Nh_l, Nout) (X_train, Y_train), (X_test, Y_test) = Data_func() history = model.fit(X_train, Y_train, epochs=5, batch_size=100, validation_split=0.2) performace_test = model.evaluate(X_test, Y_test, batch_size=100) print('Test Loss and Accuracy ->', performace_test) plot_loss(history) plt.show() plot_acc(history) plt.show()
def main(): Nh_l = [100, 50] Pd_l = [0.0, 0.0] number_of_class = 10 Nout = number_of_class (X_train, Y_train), (X_test, Y_test) = Data_func() model = DNN(X_train.shape[1], Nh_l, Pd_l, Nout) history = model.fit(X_train, Y_train, epochs=10, batch_size=100, validation_split=0.2) performace_test = model.evaluate(X_test, Y_test, batch_size=100) print('Test Loss and Accuracy ->', performace_test) plot_loss(history, '(a) 손실 추이') plt.show() plot_acc(history, '(b) 정확도 추이') plt.show()
def main(epochs=20, batch_size=128): data = DATA() autoencoder = AE(data.input_shape) history = autoencoder.fit(data.x_train, data.x_train, epochs=epochs, batch_size=batch_size, shuffle=True, validation_split=0.2) plot_acc(history, '(a) Accuracy') plt.show() plot_loss(history, '(b) Cost') plt.show() show_ae(autoencoder, data) plt.show()
def main(): Nin = 784 Nh_l = [100, 50] number_of_class = 10 Nout = number_of_class (X_train, Y_train), (X_test, Y_test) = Data_func() model = DNN(Nin, Nh_l, Nout) history = model.fit(X_train, y_train, epochs=10, batch_size=100, validation_split=0.2) performace_test = model.evaluate(X_test, y_test, batch_size=100) print('Test Loss and Accuracy ->', performace_test) plot_acc(history) plt.show() plot_loss(history) plt.show()
def main(): x_nodes = 784 z_dim = 36 autoencoder = AE(x_nodes, z_dim) history = autoencoder.fit(X_train, X_train, epochs=10, batch_size=256, shuffle=True, validation_data=(X_test, X_test)) plot_acc(history, '(a) Accuracy Change') plt.show() plot_loss(history, '(b) Loss Change') plt.show() show_ae(autoencoder) plt.show()
def main(): x_nodes = 784 z_dim = 36 autoencoder = AE(x_nodes, z_dim) history = autoencoder.fit(X_train, X_train, epochs=500, batch_size=256, shuffle=True, validation_data=(X_test, X_test)) plot_acc(history, '(a) 학습 경과에 따른 정확도 변화 추이') plt.show() plot_loss(history, '(b) 학습 경과에 따른 손실값 변화 추이') plt.show() show_ae(autoencoder) plt.show()
def main(): Nin = 784 Nh = 100 number_of_class = 10 Nout = number_of_class # model = ANN_models_func(Nin, Nh, Nout) # model = ANN_seq_func(Nin, Nh, Nout) # model = ANN_models_class(Nin, Nh, Nout) model = ANN_seq_class(Nin, Nh, Nout) (X_train, Y_train), (X_test, Y_test) = Data_func() history = model.fit(X_train, Y_train, epochs=5, batch_size=100, validation_split=0.2) performace_test = model.evaluate(X_test, Y_test, batch_size=100) print('Test Loss and Accuracy ->', performace_test) plot_loss(history) plt.show() plot_acc(history) plt.show()
def run(self, epochs=100, batch_size=128, verbose=1): data = self.data model = self.model fig = self.fig history = self.fit(epochs=epochs, batch_size=batch_size, verbose=verbose) score = model.evaluate(data.X_test, data.Y_test, verbose=0) print('Confusion matrix') Y_test_pred = model.predict(data.X_test, verbose=0) y_test_pred = np.argmax(Y_test_pred, axis=1) print(metrics.confusion_matrix(data.y_test, y_test_pred)) print('Test score:', score[0]) print('Test accuracy:', score[1]) # Save results suffix = sfile.unique_filename('datatime') foldname = 'output_' + suffix os.makedirs(foldname) skeras.save_history_history('history_history.npy', history.history, fold=foldname) model.save_weights(os.path.join(foldname, 'dl_model.h5')) print('Output results are saved in', foldname) if fig: plt.figure(figsize=(12, 4)) plt.subplot(1, 2, 1) skeras.plot_acc(history) plt.subplot(1, 2, 2) skeras.plot_loss(history) plt.show() self.history = history return foldname
def main(): batch_size = 128 epochs = 10 data = DATA() model = CNN(data.input_shape, data.num_classes) history = model.fit(data.x_train, data.y_train, batch_size=batch_size, epochs=epochs, validation_split=0.2) score = model.evaluate(data.x_test, data.y_test) print() print('Test loss:', score[0]) print('Test accuracy:', score[1]) plot_loss(history) plt.show() plot_acc(history) plt.show()