def train(self): msg = QtWidgets.QMessageBox() load_train = LoadData() if self.lblHasil.text() != "": self.lblHasil.setText("") if self.txtLR.text() == "" or self.txtEpoch.text() == "": # Show Message msg.setIcon(msg.Information) msg.setWindowTitle("Peringatan") msg.setText("Isi Learning Rate atau Epoch terlebih dahulu!") msg.exec_() else: # print(self.txtEpoch.text()) # print(self.txtLR.text()) self.data_train = load_train.data_train self.train_generator, self.x_train, self.x_valid, self.y_train, self.y_valid = load_train.loadDataTrain( ) self.input_shape = (load_train.img_rows, load_train.img_cols, 1) epo = self.txtEpoch.text() epo = int(epo) lr = self.txtLR.text() lr = float(lr) batch_size = 32 cnn = CNN(self.input_shape, len(self.train_generator.class_indices), lr) model = cnn.ConvNetModel() self.progressBar.setMinimum(0) self.progressBar.setMaximum(epo) history = model.fit(self.x_train, self.y_train, batch_size=batch_size, epochs=epo, verbose=1, validation_data=(self.x_valid, self.y_valid)) self.progressBar.setValue(epo) evaluation = model.evaluate(self.x_valid, self.y_valid, batch_size=batch_size, verbose=1) print('loss : %.2f, accuracy : %.2f' % (evaluation[0], evaluation[1])) self.lblHasil.setText('Hasil Pelatihan: ' 'Loss : %.2f, ' 'Accuracy : %.2f%%' % (evaluation[0], evaluation[1] * 100)) model.save('./model.h5') plt.plot(history.history['acc']) plt.plot(history.history['val_acc']) plt.title('Akurasi Model') plt.ylabel('Akurasi') plt.xlabel('Epoch') plt.legend(['train', 'test'], loc='upper right') plt.show()