batch_size = 16, epochs = 20, validation_split= 0.25, verbose = 2, ) # model_test testEvaluate = model.evaluate(xTestData, yTestData, verbose=0) print("loss: " + str(testEvaluate[0]) + "\t accuracy: " + str(testEvaluate[1])) #%% Save weights model.save("my_h5_model.h5") model.save_weights("covid19_weights.h5") #%% Load weights model.load_weights("my_h5_model.h5") #%% Plotting print(history.history.keys()) #Accuracy and Loss accuracy = history.history['accuracy'] val_accuracy = history.history['val_accuracy'] loss = history.history['loss'] val_loss = history.history['val_loss'] epochs = range(len(accuracy)) plt.plot(epochs, accuracy, 'b', label='Training accuracy', color="green") plt.plot(epochs, val_accuracy, 'b', label='Validation accuracy', color="blue") plt.title('Training and validation accuracy')
from keras.preprocessing.image import ImageDataGenerator if __name__ == "__main__": path_test = "./test/" obj_weight = "model_w.h5" shape = (128, 512) shape_t = (128, 512, 1) model = CNN(shape_t) if not os.path.exists(obj_weight): raise ValueError("Can't find model weights") model.load_weights(obj_weight) data_gen = ImageDataGenerator() batch_size = 2 test_gen = data_gen.flow_from_directory(path_test, batch_size=batch_size, target_size=shape, class_mode='categorical', color_mode='grayscale') results = model.evaluate_generator(test_gen) print("Results:: \n\n", results) # loss, roc_auc, accuracy