mimg = MoleImages() X_test, y_test = mimg.load_test_images('data_scaled_test/benign', 'data_scaled_test/malign') mycnn = CNN() train_datagen = ImageDataGenerator( vertical_flip=True, horizontal_flip=True) test_datagen = ImageDataGenerator() train_generator = train_datagen.flow_from_directory( train_data_dir, target_size=(128, 128), batch_size=batch_size, class_mode='binary') validation_generator = test_datagen.flow_from_directory( validation_data_dir, target_size=(128, 128), batch_size=batch_size, class_mode='binary') model = mycnn.fit_generator(train_generator,validation_generator, nb_train_samples, nb_validation_samples, epochs, batch_size) model.save('models/mymodel-3.h5') y_pred_proba = model.predict(X_test) y_pred = (y_pred_proba >0.5)*1 print(classification_report(y_test,y_pred)) plot_roc(y_test, y_pred_proba, title='ROC Curve CNN from scratch')
validation_generator = test_datagen.flow_from_directory( validation_data_dir, target_size=(128, 128), batch_size=batch_size, class_mode='binary') best_model_VA = ModelCheckpoint('BM_VA_' + model_path, monitor='val_acc', mode='max', verbose=1, save_best_only=True) best_model_VL = ModelCheckpoint('BM_VL_' + model_path, monitor='val_loss', mode='min', verbose=1, save_best_only=True) model = mycnn.fit_generator(train_generator, validation_generator, 10 * nb_train_samples, nb_validation_samples, epochs, batch_size, callbacks=[best_model_VA, best_model_VL]) model.save(model_path) #y_pred_proba = model.predict(X_test) #y_pred = (y_pred_proba >0.5)*1 #print(classification_report(y_test,y_pred)) #plot_roc(y_test, y_pred_proba, title='ROC Curve CNN from scratch')