import os
os.system ("pip install keras==2.4.3")
import keras
print('The keras version is {}.'.format(keras.__version__))
The keras version is 2.4.3.
# IPython display functions
import IPython
from IPython.display import display, HTML, SVG, Image
# General Plotting
import matplotlib.pyplot as plt
plt.style.use('seaborn-paper')
plt.rcParams['figure.figsize'] = [10, 6] ## plot size
plt.rcParams['axes.linewidth'] = 2.0 #set the value globally
## notebook style and settings
display(HTML("<style>.container { width:90% !important; }</style>"))
display(HTML("<style>.output_png { display: table-cell; text-align: center; vertical-align: middle; } </style>"))
display(HTML("<style>.MathJax {font-size: 100%;}</style>"))
# For changing background color
def set_background(color):
script = ( "var cell = this.closest('.code_cell');" "var editor = cell.querySelector('.input_area');" "editor.style.background='{}';" "this.parentNode.removeChild(this)" ).format(color)
display(HTML('<img src onerror="{}">'.format(script)))
import os
import sys
import random
import numpy as np
import pandas as pd
from os import walk
# Metrics
from sklearn.metrics import *
# Keras library for deep learning
# https://keras.io/
import tensorflow as tf
import keras
from keras.datasets import mnist # MNIST Data set
from keras.models import Sequential # Model building
from keras.layers import * # Model layers
from keras.preprocessing.image import *
from sklearn.model_selection import train_test_split
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
def displayConfusionMatrix(confusionMatrix, precisionNegative, precisionPositive, recallNegative, recallPositive, title):
# Set font size for the plots. You can ignore this line.
PLOT_FONT_SIZE = 14
# Set plot size. Please ignore this line
plt.rcParams['figure.figsize'] = [5, 5]
# Transpose of confusion matrix to align the plot with the actual precision recall values. Please ignore this as well.
confusionMatrix = np.transpose(confusionMatrix)
# Plotting the confusion matrix
plt.imshow(confusionMatrix, interpolation='nearest',cmap=plt.cm.Blues, vmin=0, vmax=100)
# Setting plot properties. You should ignore everything from here on.
xticks = np.array([-0.5, 0, 1,1.5])
plt.gca().set_xticks(xticks)
plt.gca().set_yticks(xticks)
plt.gca().set_xticklabels(["", "Healthy\nRecall=" + str(recallNegative) , "Pneumonia\nRecall=" + str(recallPositive), ""], fontsize=PLOT_FONT_SIZE)
plt.gca().set_yticklabels(["", "Healthy\nPrecision=" + str(precisionNegative) , "Pneumonia\nPrecision=" + str(precisionPositive), ""], fontsize=PLOT_FONT_SIZE)
plt.ylabel("Predicted Class", fontsize=PLOT_FONT_SIZE)
plt.xlabel("Actual Class", fontsize=PLOT_FONT_SIZE)
plt.title(title, fontsize=PLOT_FONT_SIZE)
# Add text in heatmap boxes
for i in range(2):
for j in range(2):
text = plt.text(j, i, confusionMatrix[i][j], ha="center", va="center", color="white", size=15) ### size here is the size of text inside a single box in the heatmap
plt.show()
def calculateMetricsAndPrint(predictions, predictionsProbabilities, actualLabels):
# Convert label format from [0,1](label 1) and [1,0](label 0) into single integers: 1 and 0.
actualLabels = [item[1] for item in actualLabels]
# Get probabilities for the class with label 1. That is all we need to compute AUCs. We don't need probabilities for class 0.
predictionsProbabilities = [item[1] for item in predictionsProbabilities]
# Calculate metrics using scikit-learn functions. The round function is used to round the numbers up to 2 decimal points.
accuracy = round(accuracy_score(actualLabels, predictions) * 100, 2)
precisionNegative = round(precision_score(actualLabels, predictions, average = None)[0] * 100, 2)
precisionPositive = round(precision_score(actualLabels, predictions, average = None)[1] * 100, 2)
recallNegative = round(recall_score(actualLabels, predictions, average = None)[0] * 100, 2)
recallPositive = round(recall_score(actualLabels, predictions, average = None)[1] * 100, 2)
auc = round(roc_auc_score(actualLabels, predictionsProbabilities) * 100, 2)
confusionMatrix = confusion_matrix(actualLabels, predictions)
# Print metrics. .%2f prints a number upto 2 decimal points only.
print("------------------------------------------------------------------------")
print("Accuracy: %.2f\nPrecisionNegative: %.2f\nPrecisionPositive: %.2f\nRecallNegative: %.2f\nRecallPositive: %.2f\nAUC Score: %.2f" %
(accuracy, precisionNegative, precisionPositive, recallNegative, recallPositive, auc))
print("------------------------------------------------------------------------")
print("+ Printing confusion matrix...\n")
# Display confusion matrix
displayConfusionMatrix(confusionMatrix, precisionNegative, precisionPositive, recallNegative, recallPositive, "Confusion Matrix")
print("+ Printing ROC curve...\n")
# ROC Curve
plt.rcParams['figure.figsize'] = [16, 8]
FONT_SIZE = 16
falsePositiveRateDt, truePositiveRateDt, _ = roc_curve(actualLabels, predictionsProbabilities)
plt.plot(falsePositiveRateDt, truePositiveRateDt, linewidth = 5, color='black')
plt.xticks(fontsize=FONT_SIZE)
plt.yticks(fontsize=FONT_SIZE)
plt.xlabel("False Positive Rate", fontsize=FONT_SIZE)
plt.ylabel("True Positive Rate", fontsize=FONT_SIZE)
plt.show()
return auc
def calculateMetrics(predictions, predictionsProbabilities, actualLabels):
# Convert label format from [0,1](label 1) and [1,0](label 0) into single integers: 1 and 0.
actualLabels = [item[1] for item in actualLabels]
# Get probabilities for the class with label 1. That is all we need to compute AUCs. We don't need probabilities for class 0.
predictionsProbabilities = [item[1] for item in predictionsProbabilities]
# Calculate metrics using scikit-learn functions. The round function is used to round the numbers up to 2 decimal points.
try:
accuracy = round(accuracy_score(actualLabels, predictions) * 100, 2)
precisionNegative = round(precision_score(actualLabels, predictions, average = None)[0] * 100, 2)
precisionPositive = round(precision_score(actualLabels, predictions, average = None)[1] * 100, 2)
recallNegative = round(recall_score(actualLabels, predictions, average = None)[0] * 100, 2)
recallPositive = round(recall_score(actualLabels, predictions, average = None)[1] * 100, 2)
except:
print("An exception occurred but was caught.")
auc = round(roc_auc_score(actualLabels, predictionsProbabilities) * 100, 2)
return auc
def getKagglePredictions(model, kaggleData, filename):
print("+ Writing kaggle test results in : results/%s..." % filename)
predictions = model.predict(kaggleData)
predictionProbs = [item[1] for item in predictions]
# Store predictions for kaggle
outputFile = open("results/" + str(filename), "w")
outputFile.write("Id,Prediction\n")
for i in range(0, len(predictionProbs)):
outputFile.write(str(i + 1) + "," + str(predictionProbs[i]) + "\n")
outputFile.close()
def calculateClasswiseTopNAccuracy(actualLabels, predictionsProbs, TOP_N):
"""
TOP_N is the top n% predictions you want to use for each class
"""
discreteActualLabels = [1 if item[1] > item[0] else 0 for item in actualLabels]
discretePredictions = [1 if item[1] > item[0] else 0 for item in predictionsProbs]
predictionProbsTopNHealthy, predictionProbsTopNPneumonia = [item[0] for item in predictionsProbs], [item[1] for item in predictionsProbs]
predictionProbsTopNHealthy = list(reversed(sorted(predictionProbsTopNHealthy)))[:int(len(predictionProbsTopNHealthy) * TOP_N / 100)][-1]
predictionProbsTopNPneumonia = list(reversed(sorted(predictionProbsTopNPneumonia)))[:int(len(predictionProbsTopNPneumonia) * TOP_N / 100)][-1]
# Calculate accuracy for both classes
accuracyHealthy = []
accuracyPneumonia = []
for i in range(0, len(discretePredictions)):
if discretePredictions[i] == 1:
# Pneumonia
if predictionsProbs[i][1] > predictionProbsTopNPneumonia:
accuracyPneumonia.append(int(discreteActualLabels[i]) == 1)
else:
# Healthy
if predictionsProbs[i][0] > predictionProbsTopNHealthy:
accuracyHealthy.append(int(discreteActualLabels[i]) == 0)
accuracyHealthy = round((accuracyHealthy.count(True) * 100) / len(accuracyHealthy), 2)
accuracyPneumonia = round((accuracyPneumonia.count(True) * 100) / len(accuracyPneumonia), 2)
return accuracyHealthy, accuracyPneumonia
# Load normal images
normalImagesPath = "data/train/normal"
normalImageFiles = []
for(_,_,files) in walk(normalImagesPath):
normalImageFiles.extend(files)
normalImagesPath2 = "data/train/normal2"
for(_,_,files) in walk(normalImagesPath2):
normalImageFiles.extend(files)
print(len(normalImageFiles))
# Load pneumonia images
pneumoniaImagesPath = "data/train/pneumonia"
pneumoniaImageFiles = []
for(_,_,files) in walk(pneumoniaImagesPath):
pneumoniaImageFiles.extend(files)
random.shuffle(pneumoniaImageFiles)
pneumoniaImageFiles = pneumoniaImageFiles[:len(normalImageFiles)]
print("Normal X-ray images: %d\nPneumonia X-ray images: %d" % (len(normalImageFiles), len(pneumoniaImageFiles)))
1436
Normal X-ray images: 1436
Pneumonia X-ray images: 1436
imagesData = []
imagesLabels = []
for file in normalImageFiles:
fullPath = normalImagesPath + "/" + file
if os.path.exists(fullPath) == False:
continue
imageData = load_img(normalImagesPath + "/" + file, color_mode = "grayscale") # load_img function comes from keras library when we do "from keras.preprocessing.image import *"
imageArray = img_to_array(imageData) / 255.0
imagesData.append(imageArray)
imagesLabels.append(0)
for file in pneumoniaImageFiles:
fullPath = pneumoniaImagesPath + "/" + file
if os.path.exists(fullPath) == False:
continue
imageData = load_img(pneumoniaImagesPath + "/" + file, color_mode = "grayscale") # load_img function comes from keras library when we do "from keras.preprocessing.image import *"
imageArray = img_to_array(imageData) / 255.0
imagesData.append(imageArray)
imagesLabels.append(1)
imagesData = np.array(imagesData)
imagesLabels = keras.utils.to_categorical(imagesLabels)
print("Input data shape: %s" % (imagesData.shape,))
Input data shape: (2154, 256, 256, 1)
testImagesPath = "data/test/"
testImageFiles = []
for(_,_,files) in walk(testImagesPath):
testImageFiles.extend(files)
testImageFiles = list(sorted(testImageFiles))
kaggleTestImages = []
for file in testImageFiles:
fullPath = testImagesPath + "/" + file
if os.path.exists(fullPath) == False:
continue
imageData = load_img(testImagesPath + "/" + file, color_mode = "grayscale") # load_img function comes from keras library when we do "from keras.preprocessing.image import *"
imageArray = img_to_array(imageData) / 255.0
kaggleTestImages.append(imageArray)
kaggleTestImages = np.array(kaggleTestImages)
print("Number of test images: %d" % len(kaggleTestImages))
Number of test images: 200
def trainTestSplit(data, labels):
"""
80-20 train-test data split
"""
trainData, trainLabels, testData, testLabels = [], [], [], []
for i in range(0, len(data)):
if i % 5 == 0:
testData.append(data[i])
testLabels.append(labels[i])
else:
trainData.append(data[i])
trainLabels.append(labels[i])
return np.array(trainData), np.array(testData), np.array(trainLabels), np.array(testLabels)
# In our context, since we have a private test data on kaggle, our test data here would actually mean validation data. We will use results on this validation(test) data to see how our model would perform on the actual test data.
# Split data into 80% training and 20% testing
trainData, testData, trainLabels, testLabels = trainTestSplit(imagesData, imagesLabels)
def createParameterizedConvolutionalNeuralNetwork(trainImages, numLayers, numFilters, kernelSize, maxPooling, dropoutValue, learningRate, numClasses):
# Create model object
model = Sequential()
# Add the first layer with dropout
model.add(Conv2D(numFilters, kernel_size=(kernelSize, kernelSize),
activation='relu', padding = 'same',
input_shape=trainImages.shape[1:]))
model.add(MaxPooling2D(pool_size=(maxPooling, maxPooling)))
model.add(Dropout(dropoutValue))
while numLayers > 1:
model.add(Conv2D(numFilters, kernel_size=(kernelSize, kernelSize),
activation='relu', padding = 'same'))
model.add(MaxPooling2D(pool_size=(maxPooling, maxPooling)))
model.add(Dropout(dropoutValue))
numLayers = numLayers - 1
# Convolutional layers are done, adding the remaining stuff. Please note that after conv layers, you should always use a Flatten() layer.
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(BatchNormalization(momentum=0.99))
model.add(Dropout(dropoutValue))
model.add(Dense(numClasses, activation='softmax'))
# Compile model. You can skip this line.
model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adam(lr=learningRate),
metrics=['accuracy'])
# Return model
return model
def createNuancedConvolutionalNeuralNetwork(trainImages, numClasses):
"""
You should try to edit this model as much as you can. Try adding/removing layers, setting different parameters for different layers etc. You have complete control of the model and you should try different things to see what works and what does not.
"""
# Create model object
model = Sequential()
# Add the first layer with dropout
model.add(Conv2D(filters = 64, kernel_size=(5, 5),
activation='relu', padding = 'same',
input_shape=trainImages.shape[1:]))
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Dropout(0.5))
# Second layer with diffefiltersrent parameters
model.add(Conv2D(filters = 32, kernel_size=(3, 3),
activation='relu', padding = 'same'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
# Convolutional layers are done, adding the remaining stuff. Please note that after conv layers, you should always use a Flatten() layer.
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(numClasses, activation='softmax'))
# Compile model. You can skip this line.
model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adam(lr=0.0001),
metrics=['accuracy'])
# Return model
return model
set_background('#fce53a')
#####################################################################################################################################################
# Things you can change
#####################################################################################################################################################
# You can change all these parameters for different results. Please go to the following links to read more about each parameter:
# https://keras.io/preprocessing/image/
# https://www.pyimagesearch.com/2019/07/08/keras-imagedatagenerator-and-data-augmentation/
dataAugmentation = ImageDataGenerator(
rotation_range=11,
width_shift_range=0.07,
height_shift_range=0.07,
horizontal_flip=True,
vertical_flip=False,
shear_range=0.0,
zoom_range=0.37)
set_background('#fce53a')
#####################################################################################################################################################
# Things you can change
#####################################################################################################################################################
numLayers = 3 # Number of layers in the neural network
numFilters = 55 # Number of units in each layer
kernelSize = 22 # filter size of a single filter
dropoutValue = 0.29 # Dropout probability
maxPooling = 3 # Max pooling
numClasses = 2 # Don't change this value for pneumonia since we have 2 classes i.e we are trying to recognize a digit among 10 digits. But for any other data set, this should be changed
batchSize = 64 # How many images should a single batch contain
learningRate = 0.0000987 # How fast should the model learn
epochs = 100
# Number of epochs to train your model for
USE_DATA_AUGMENTATION = True # You can set it to false if you do not want to use data augmentation. We recommend trying both true and false.
#####################################################################################################################################################
# Please do not change this line.
dataAugmentation.fit(trainData) # Training the augmentor in case we set USE_DATA_AUGMENTATION to True.
# Create model
parameterizedModel = createParameterizedConvolutionalNeuralNetwork(trainData, numLayers, numFilters, kernelSize, maxPooling, dropoutValue, learningRate, numClasses = 2)
print("+ Your parameterized model has been created...")
+ Your parameterized model has been created...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py:375: UserWarning: The `lr` argument is deprecated, use `learning_rate` instead.
"The `lr` argument is deprecated, use `learning_rate` instead.")
# You can create the other model with the following line
nonParameterizedModel = createNuancedConvolutionalNeuralNetwork(imagesData, numClasses = 2)
print("+ Your non parameterized model has been created...")
+ Your non parameterized model has been created...
#####################################################################################################################################################
# Things you can change
#####################################################################################################################################################
# Please assign model the deep learning model you want to use i.e parameterizedModel or nonParameterizedModel
model = parameterizedModel
bestAcc = 0.0
bestEpoch = 0
bestAccPredictions, bestAccPredictionProbabilities = [], []
print("+ Starting training. Each epoch can take about 2-5 minutes, hold tight!")
print("-----------------------------------------------------------------------\n")
for epoch in range(epochs):
#################################################### Model Training ###############################################################
if USE_DATA_AUGMENTATION == True:
# Use data augmentation in alternate epochs
if epoch % 2 == 0:
# Alternate between training with and without augmented data. Training just on the augmented data might not be the best way to go.
############ You can change the "epoch % 2" to some other integer value to train on top of the augmented data
############ after a certain number of epochs e.g "epoch % 3" will train on augmented data after every 2 epochs ############
model.fit_generator(dataAugmentation.flow(trainData, trainLabels, batch_size=batchSize),
steps_per_epoch=len(trainData) / batchSize, epochs=1, verbose = 2)
else:
model.fit(trainData, trainLabels, batch_size=batchSize, epochs=1, verbose = 2)
else:
# Do not use data augmentation
model.fit(trainData, trainLabels, batch_size=batchSize, epochs=1, verbose = 2)
#################################################### Model Testing ###############################################################
# Calculate test accuracy
accuracy = round(model.evaluate(testData, testLabels)[1] * 100, 3)
predictions = model.predict(testData)
#get epoch-level AUCs
AccPredictionProbabilities = model.predict(testData)
AccPredictions = [1 if item[1] > item[0] else 0 for item in AccPredictionProbabilities]
epochAUC = calculateMetrics(AccPredictions, AccPredictionProbabilities, testLabels)
print("+ Test accuracy at epoch %d is: %.2f " % (epoch, accuracy))
print("+ Test AUC at epoch %d is: %.3f " % (epoch, epochAUC))
if accuracy > bestAcc:
bestEpoch = epoch
bestAcc = accuracy
bestAccPredictions = [1 if item[1] > item[0] else 0 for item in predictions]
bestAccPredictionProbabilities = predictions
##################################### Store predictions for kaggle ###########################################################
kaggleResultsFileName = "epoch-" + str(epoch) + "-results.csv"
getKagglePredictions(model, kaggleTestImages, kaggleResultsFileName)
##############################################################################################################################
print('\n')
print("------------------------------------------------------------------------")
##################################################### Printing best metrics ##########################################################
# Get more metrics for the best performing epoch
print("\n*** Printing our best validation results that we obtained in epoch %d ..." % bestEpoch)
calculateMetricsAndPrint(bestAccPredictions, bestAccPredictionProbabilities, testLabels)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
+ Starting training. Each epoch can take about 2-5 minutes, hold tight!
-----------------------------------------------------------------------
26/26 - 110s - loss: 0.9933 - accuracy: 0.5369
14/14 [==============================] - 14s 295ms/step - loss: 0.7453 - accuracy: 0.3411
+ Test accuracy at epoch 0 is: 34.11
+ Test AUC at epoch 0 is: 78.020
+ Writing kaggle test results in : results/epoch-0-results.csv...
27/27 - 20s - loss: 0.8410 - accuracy: 0.5914
14/14 [==============================] - 2s 171ms/step - loss: 0.5799 - accuracy: 0.8515
+ Test accuracy at epoch 1 is: 85.15
+ Test AUC at epoch 1 is: 93.030
+ Writing kaggle test results in : results/epoch-1-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.6483 - accuracy: 0.6947
14/14 [==============================] - 2s 170ms/step - loss: 0.6035 - accuracy: 0.6659
/shared-libs/python3.6/py/lib/python3.6/site-packages/sklearn/metrics/_classification.py:1248: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
/shared-libs/python3.6/py/lib/python3.6/site-packages/sklearn/metrics/_classification.py:1248: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
+ Test accuracy at epoch 2 is: 66.59
+ Test AUC at epoch 2 is: 92.660
+ Writing kaggle test results in : results/epoch-2-results.csv...
27/27 - 20s - loss: 0.4403 - accuracy: 0.8021
14/14 [==============================] - 2s 170ms/step - loss: 0.6086 - accuracy: 0.6659
/shared-libs/python3.6/py/lib/python3.6/site-packages/sklearn/metrics/_classification.py:1248: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
/shared-libs/python3.6/py/lib/python3.6/site-packages/sklearn/metrics/_classification.py:1248: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
+ Test accuracy at epoch 3 is: 66.59
+ Test AUC at epoch 3 is: 97.150
+ Writing kaggle test results in : results/epoch-3-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.4621 - accuracy: 0.7916
14/14 [==============================] - 2s 170ms/step - loss: 0.6026 - accuracy: 0.6659
/shared-libs/python3.6/py/lib/python3.6/site-packages/sklearn/metrics/_classification.py:1248: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
/shared-libs/python3.6/py/lib/python3.6/site-packages/sklearn/metrics/_classification.py:1248: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
+ Test accuracy at epoch 4 is: 66.59
+ Test AUC at epoch 4 is: 95.260
+ Writing kaggle test results in : results/epoch-4-results.csv...
27/27 - 19s - loss: 0.3273 - accuracy: 0.8717
14/14 [==============================] - 2s 171ms/step - loss: 0.5539 - accuracy: 0.8492
+ Test accuracy at epoch 5 is: 84.92
+ Test AUC at epoch 5 is: 97.980
+ Writing kaggle test results in : results/epoch-5-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3836 - accuracy: 0.8456
14/14 [==============================] - 2s 170ms/step - loss: 0.5753 - accuracy: 0.7355
+ Test accuracy at epoch 6 is: 73.55
+ Test AUC at epoch 6 is: 96.510
+ Writing kaggle test results in : results/epoch-6-results.csv...
27/27 - 19s - loss: 0.3024 - accuracy: 0.8903
14/14 [==============================] - 2s 170ms/step - loss: 0.5335 - accuracy: 0.9026
+ Test accuracy at epoch 7 is: 90.25
+ Test AUC at epoch 7 is: 97.770
+ Writing kaggle test results in : results/epoch-7-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3729 - accuracy: 0.8514
14/14 [==============================] - 2s 170ms/step - loss: 0.5833 - accuracy: 0.6682
+ Test accuracy at epoch 8 is: 66.82
+ Test AUC at epoch 8 is: 96.670
+ Writing kaggle test results in : results/epoch-8-results.csv...
27/27 - 20s - loss: 0.2779 - accuracy: 0.8961
14/14 [==============================] - 2s 171ms/step - loss: 0.4731 - accuracy: 0.9211
+ Test accuracy at epoch 9 is: 92.11
+ Test AUC at epoch 9 is: 98.130
+ Writing kaggle test results in : results/epoch-9-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3592 - accuracy: 0.8508
14/14 [==============================] - 2s 170ms/step - loss: 0.5357 - accuracy: 0.6775
+ Test accuracy at epoch 10 is: 67.75
+ Test AUC at epoch 10 is: 97.110
+ Writing kaggle test results in : results/epoch-10-results.csv...
27/27 - 19s - loss: 0.2440 - accuracy: 0.9112
14/14 [==============================] - 2s 170ms/step - loss: 0.5075 - accuracy: 0.7053
+ Test accuracy at epoch 11 is: 70.53
+ Test AUC at epoch 11 is: 97.410
+ Writing kaggle test results in : results/epoch-11-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3504 - accuracy: 0.8578
14/14 [==============================] - 2s 171ms/step - loss: 0.4693 - accuracy: 0.9304
+ Test accuracy at epoch 12 is: 93.04
+ Test AUC at epoch 12 is: 97.980
+ Writing kaggle test results in : results/epoch-12-results.csv...
27/27 - 19s - loss: 0.1972 - accuracy: 0.9373
14/14 [==============================] - 2s 171ms/step - loss: 0.3898 - accuracy: 0.8422
+ Test accuracy at epoch 13 is: 84.22
+ Test AUC at epoch 13 is: 98.340
+ Writing kaggle test results in : results/epoch-13-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3728 - accuracy: 0.8450
14/14 [==============================] - 2s 170ms/step - loss: 0.4637 - accuracy: 0.7657
+ Test accuracy at epoch 14 is: 76.57
+ Test AUC at epoch 14 is: 96.810
+ Writing kaggle test results in : results/epoch-14-results.csv...
27/27 - 19s - loss: 0.2342 - accuracy: 0.9205
14/14 [==============================] - 2s 171ms/step - loss: 0.3568 - accuracy: 0.8515
+ Test accuracy at epoch 15 is: 85.15
+ Test AUC at epoch 15 is: 98.270
+ Writing kaggle test results in : results/epoch-15-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3064 - accuracy: 0.8799
14/14 [==============================] - 2s 170ms/step - loss: 0.3540 - accuracy: 0.8469
+ Test accuracy at epoch 16 is: 84.69
+ Test AUC at epoch 16 is: 98.090
+ Writing kaggle test results in : results/epoch-16-results.csv...
27/27 - 19s - loss: 0.1967 - accuracy: 0.9315
14/14 [==============================] - 2s 170ms/step - loss: 0.2782 - accuracy: 0.9234
+ Test accuracy at epoch 17 is: 92.34
+ Test AUC at epoch 17 is: 98.480
+ Writing kaggle test results in : results/epoch-17-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3174 - accuracy: 0.8828
14/14 [==============================] - 2s 170ms/step - loss: 0.2924 - accuracy: 0.8956
+ Test accuracy at epoch 18 is: 89.56
+ Test AUC at epoch 18 is: 97.630
+ Writing kaggle test results in : results/epoch-18-results.csv...
27/27 - 19s - loss: 0.1854 - accuracy: 0.9344
14/14 [==============================] - 2s 170ms/step - loss: 0.2410 - accuracy: 0.9258
+ Test accuracy at epoch 19 is: 92.58
+ Test AUC at epoch 19 is: 98.270
+ Writing kaggle test results in : results/epoch-19-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3162 - accuracy: 0.8781
14/14 [==============================] - 2s 171ms/step - loss: 0.3138 - accuracy: 0.8677
+ Test accuracy at epoch 20 is: 86.78
+ Test AUC at epoch 20 is: 98.070
+ Writing kaggle test results in : results/epoch-20-results.csv...
27/27 - 19s - loss: 0.1903 - accuracy: 0.9362
14/14 [==============================] - 2s 170ms/step - loss: 0.1952 - accuracy: 0.9443
+ Test accuracy at epoch 21 is: 94.43
+ Test AUC at epoch 21 is: 98.570
+ Writing kaggle test results in : results/epoch-21-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2978 - accuracy: 0.8874
14/14 [==============================] - 2s 171ms/step - loss: 0.2008 - accuracy: 0.9350
+ Test accuracy at epoch 22 is: 93.50
+ Test AUC at epoch 22 is: 98.000
+ Writing kaggle test results in : results/epoch-22-results.csv...
27/27 - 19s - loss: 0.1736 - accuracy: 0.9402
14/14 [==============================] - 2s 171ms/step - loss: 0.1885 - accuracy: 0.9327
+ Test accuracy at epoch 23 is: 93.27
+ Test AUC at epoch 23 is: 98.540
+ Writing kaggle test results in : results/epoch-23-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2747 - accuracy: 0.9002
14/14 [==============================] - 2s 171ms/step - loss: 0.2011 - accuracy: 0.9327
+ Test accuracy at epoch 24 is: 93.27
+ Test AUC at epoch 24 is: 98.010
+ Writing kaggle test results in : results/epoch-24-results.csv...
27/27 - 19s - loss: 0.1523 - accuracy: 0.9414
14/14 [==============================] - 2s 171ms/step - loss: 0.1712 - accuracy: 0.9327
+ Test accuracy at epoch 25 is: 93.27
+ Test AUC at epoch 25 is: 98.580
+ Writing kaggle test results in : results/epoch-25-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2912 - accuracy: 0.8862
14/14 [==============================] - 2s 170ms/step - loss: 0.3283 - accuracy: 0.8747
+ Test accuracy at epoch 26 is: 87.47
+ Test AUC at epoch 26 is: 98.610
+ Writing kaggle test results in : results/epoch-26-results.csv...
27/27 - 19s - loss: 0.1518 - accuracy: 0.9472
14/14 [==============================] - 2s 171ms/step - loss: 0.1853 - accuracy: 0.9350
+ Test accuracy at epoch 27 is: 93.50
+ Test AUC at epoch 27 is: 98.370
+ Writing kaggle test results in : results/epoch-27-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2610 - accuracy: 0.8961
14/14 [==============================] - 2s 171ms/step - loss: 0.2668 - accuracy: 0.8817
+ Test accuracy at epoch 28 is: 88.17
+ Test AUC at epoch 28 is: 98.130
+ Writing kaggle test results in : results/epoch-28-results.csv...
27/27 - 19s - loss: 0.1533 - accuracy: 0.9425
14/14 [==============================] - 2s 170ms/step - loss: 0.1533 - accuracy: 0.9443
+ Test accuracy at epoch 29 is: 94.43
+ Test AUC at epoch 29 is: 98.760
+ Writing kaggle test results in : results/epoch-29-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3107 - accuracy: 0.8804
14/14 [==============================] - 2s 170ms/step - loss: 0.5248 - accuracy: 0.7726
+ Test accuracy at epoch 30 is: 77.26
+ Test AUC at epoch 30 is: 97.740
+ Writing kaggle test results in : results/epoch-30-results.csv...
27/27 - 20s - loss: 0.1521 - accuracy: 0.9425
14/14 [==============================] - 2s 170ms/step - loss: 0.1778 - accuracy: 0.9281
+ Test accuracy at epoch 31 is: 92.81
+ Test AUC at epoch 31 is: 98.510
+ Writing kaggle test results in : results/epoch-31-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2852 - accuracy: 0.8903
14/14 [==============================] - 2s 170ms/step - loss: 0.1875 - accuracy: 0.9327
+ Test accuracy at epoch 32 is: 93.27
+ Test AUC at epoch 32 is: 98.540
+ Writing kaggle test results in : results/epoch-32-results.csv...
27/27 - 19s - loss: 0.1335 - accuracy: 0.9518
14/14 [==============================] - 2s 170ms/step - loss: 0.3285 - accuracy: 0.8817
+ Test accuracy at epoch 33 is: 88.17
+ Test AUC at epoch 33 is: 98.420
+ Writing kaggle test results in : results/epoch-33-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.3205 - accuracy: 0.8787
14/14 [==============================] - 2s 171ms/step - loss: 0.2414 - accuracy: 0.8956
+ Test accuracy at epoch 34 is: 89.56
+ Test AUC at epoch 34 is: 98.270
+ Writing kaggle test results in : results/epoch-34-results.csv...
27/27 - 19s - loss: 0.1426 - accuracy: 0.9524
14/14 [==============================] - 2s 170ms/step - loss: 0.1921 - accuracy: 0.9327
+ Test accuracy at epoch 35 is: 93.27
+ Test AUC at epoch 35 is: 98.780
+ Writing kaggle test results in : results/epoch-35-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2303 - accuracy: 0.9153
14/14 [==============================] - 2s 171ms/step - loss: 0.1463 - accuracy: 0.9513
+ Test accuracy at epoch 36 is: 95.13
+ Test AUC at epoch 36 is: 98.650
+ Writing kaggle test results in : results/epoch-36-results.csv...
27/27 - 19s - loss: 0.1268 - accuracy: 0.9600
14/14 [==============================] - 2s 170ms/step - loss: 0.4519 - accuracy: 0.8051
+ Test accuracy at epoch 37 is: 80.51
+ Test AUC at epoch 37 is: 98.740
+ Writing kaggle test results in : results/epoch-37-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2669 - accuracy: 0.8973
14/14 [==============================] - 2s 171ms/step - loss: 0.1959 - accuracy: 0.9234
+ Test accuracy at epoch 38 is: 92.34
+ Test AUC at epoch 38 is: 98.820
+ Writing kaggle test results in : results/epoch-38-results.csv...
27/27 - 19s - loss: 0.1179 - accuracy: 0.9547
14/14 [==============================] - 2s 171ms/step - loss: 0.1546 - accuracy: 0.9443
+ Test accuracy at epoch 39 is: 94.43
+ Test AUC at epoch 39 is: 98.910
+ Writing kaggle test results in : results/epoch-39-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2258 - accuracy: 0.9228
14/14 [==============================] - 2s 170ms/step - loss: 0.1797 - accuracy: 0.9327
+ Test accuracy at epoch 40 is: 93.27
+ Test AUC at epoch 40 is: 98.480
+ Writing kaggle test results in : results/epoch-40-results.csv...
27/27 - 19s - loss: 0.1129 - accuracy: 0.9588
14/14 [==============================] - 2s 170ms/step - loss: 0.1516 - accuracy: 0.9536
+ Test accuracy at epoch 41 is: 95.36
+ Test AUC at epoch 41 is: 98.890
+ Writing kaggle test results in : results/epoch-41-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2522 - accuracy: 0.9019
14/14 [==============================] - 2s 171ms/step - loss: 0.1500 - accuracy: 0.9466
+ Test accuracy at epoch 42 is: 94.66
+ Test AUC at epoch 42 is: 98.660
+ Writing kaggle test results in : results/epoch-42-results.csv...
27/27 - 19s - loss: 0.1354 - accuracy: 0.9541
14/14 [==============================] - 2s 171ms/step - loss: 0.1736 - accuracy: 0.9350
+ Test accuracy at epoch 43 is: 93.50
+ Test AUC at epoch 43 is: 98.760
+ Writing kaggle test results in : results/epoch-43-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2225 - accuracy: 0.9153
14/14 [==============================] - 2s 170ms/step - loss: 0.1521 - accuracy: 0.9443
+ Test accuracy at epoch 44 is: 94.43
+ Test AUC at epoch 44 is: 98.580
+ Writing kaggle test results in : results/epoch-44-results.csv...
27/27 - 19s - loss: 0.1064 - accuracy: 0.9640
14/14 [==============================] - 2s 170ms/step - loss: 0.1285 - accuracy: 0.9536
+ Test accuracy at epoch 45 is: 95.36
+ Test AUC at epoch 45 is: 98.800
+ Writing kaggle test results in : results/epoch-45-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2369 - accuracy: 0.9042
14/14 [==============================] - 2s 171ms/step - loss: 0.1406 - accuracy: 0.9466
+ Test accuracy at epoch 46 is: 94.66
+ Test AUC at epoch 46 is: 98.570
+ Writing kaggle test results in : results/epoch-46-results.csv...
27/27 - 19s - loss: 0.1161 - accuracy: 0.9617
14/14 [==============================] - 2s 171ms/step - loss: 0.1271 - accuracy: 0.9536
+ Test accuracy at epoch 47 is: 95.36
+ Test AUC at epoch 47 is: 98.940
+ Writing kaggle test results in : results/epoch-47-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2349 - accuracy: 0.9095
14/14 [==============================] - 2s 171ms/step - loss: 0.1677 - accuracy: 0.9350
+ Test accuracy at epoch 48 is: 93.50
+ Test AUC at epoch 48 is: 98.640
+ Writing kaggle test results in : results/epoch-48-results.csv...
27/27 - 19s - loss: 0.0953 - accuracy: 0.9652
14/14 [==============================] - 2s 171ms/step - loss: 0.1249 - accuracy: 0.9490
+ Test accuracy at epoch 49 is: 94.90
+ Test AUC at epoch 49 is: 98.900
+ Writing kaggle test results in : results/epoch-49-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2183 - accuracy: 0.9182
14/14 [==============================] - 2s 171ms/step - loss: 0.1789 - accuracy: 0.9327
+ Test accuracy at epoch 50 is: 93.27
+ Test AUC at epoch 50 is: 98.940
+ Writing kaggle test results in : results/epoch-50-results.csv...
27/27 - 19s - loss: 0.0919 - accuracy: 0.9681
14/14 [==============================] - 2s 170ms/step - loss: 0.1882 - accuracy: 0.9281
+ Test accuracy at epoch 51 is: 92.81
+ Test AUC at epoch 51 is: 99.050
+ Writing kaggle test results in : results/epoch-51-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2490 - accuracy: 0.9083
14/14 [==============================] - 2s 170ms/step - loss: 0.2876 - accuracy: 0.8956
+ Test accuracy at epoch 52 is: 89.56
+ Test AUC at epoch 52 is: 98.600
+ Writing kaggle test results in : results/epoch-52-results.csv...
27/27 - 19s - loss: 0.1072 - accuracy: 0.9605
14/14 [==============================] - 2s 171ms/step - loss: 0.2376 - accuracy: 0.9072
+ Test accuracy at epoch 53 is: 90.72
+ Test AUC at epoch 53 is: 98.740
+ Writing kaggle test results in : results/epoch-53-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2636 - accuracy: 0.8950
14/14 [==============================] - 2s 171ms/step - loss: 0.1465 - accuracy: 0.9397
+ Test accuracy at epoch 54 is: 93.97
+ Test AUC at epoch 54 is: 98.820
+ Writing kaggle test results in : results/epoch-54-results.csv...
27/27 - 19s - loss: 0.0871 - accuracy: 0.9768
14/14 [==============================] - 2s 170ms/step - loss: 0.1140 - accuracy: 0.9559
+ Test accuracy at epoch 55 is: 95.59
+ Test AUC at epoch 55 is: 99.200
+ Writing kaggle test results in : results/epoch-55-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2170 - accuracy: 0.9216
14/14 [==============================] - 2s 171ms/step - loss: 0.1340 - accuracy: 0.9513
+ Test accuracy at epoch 56 is: 95.13
+ Test AUC at epoch 56 is: 98.820
+ Writing kaggle test results in : results/epoch-56-results.csv...
27/27 - 19s - loss: 0.0824 - accuracy: 0.9745
14/14 [==============================] - 2s 171ms/step - loss: 0.1140 - accuracy: 0.9536
+ Test accuracy at epoch 57 is: 95.36
+ Test AUC at epoch 57 is: 99.190
+ Writing kaggle test results in : results/epoch-57-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2199 - accuracy: 0.9205
14/14 [==============================] - 2s 170ms/step - loss: 0.1382 - accuracy: 0.9443
+ Test accuracy at epoch 58 is: 94.43
+ Test AUC at epoch 58 is: 98.720
+ Writing kaggle test results in : results/epoch-58-results.csv...
27/27 - 19s - loss: 0.0978 - accuracy: 0.9704
14/14 [==============================] - 2s 171ms/step - loss: 0.1187 - accuracy: 0.9513
+ Test accuracy at epoch 59 is: 95.13
+ Test AUC at epoch 59 is: 99.070
+ Writing kaggle test results in : results/epoch-59-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2355 - accuracy: 0.9164
14/14 [==============================] - 2s 171ms/step - loss: 0.1825 - accuracy: 0.9304
+ Test accuracy at epoch 60 is: 93.04
+ Test AUC at epoch 60 is: 98.590
+ Writing kaggle test results in : results/epoch-60-results.csv...
27/27 - 19s - loss: 0.0856 - accuracy: 0.9710
14/14 [==============================] - 2s 171ms/step - loss: 0.1298 - accuracy: 0.9559
+ Test accuracy at epoch 61 is: 95.59
+ Test AUC at epoch 61 is: 99.010
+ Writing kaggle test results in : results/epoch-61-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2072 - accuracy: 0.9211
14/14 [==============================] - 2s 170ms/step - loss: 0.2707 - accuracy: 0.8956
+ Test accuracy at epoch 62 is: 89.56
+ Test AUC at epoch 62 is: 98.670
+ Writing kaggle test results in : results/epoch-62-results.csv...
27/27 - 19s - loss: 0.0958 - accuracy: 0.9658
14/14 [==============================] - 2s 171ms/step - loss: 0.2513 - accuracy: 0.9118
+ Test accuracy at epoch 63 is: 91.18
+ Test AUC at epoch 63 is: 98.890
+ Writing kaggle test results in : results/epoch-63-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2084 - accuracy: 0.9240
14/14 [==============================] - 2s 171ms/step - loss: 0.2517 - accuracy: 0.9026
+ Test accuracy at epoch 64 is: 90.25
+ Test AUC at epoch 64 is: 98.730
+ Writing kaggle test results in : results/epoch-64-results.csv...
27/27 - 19s - loss: 0.0710 - accuracy: 0.9756
14/14 [==============================] - 2s 170ms/step - loss: 0.1368 - accuracy: 0.9490
+ Test accuracy at epoch 65 is: 94.90
+ Test AUC at epoch 65 is: 98.980
+ Writing kaggle test results in : results/epoch-65-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.1994 - accuracy: 0.9292
14/14 [==============================] - 2s 170ms/step - loss: 0.3078 - accuracy: 0.8701
+ Test accuracy at epoch 66 is: 87.01
+ Test AUC at epoch 66 is: 98.530
+ Writing kaggle test results in : results/epoch-66-results.csv...
27/27 - 19s - loss: 0.0780 - accuracy: 0.9739
14/14 [==============================] - 2s 170ms/step - loss: 0.1191 - accuracy: 0.9606
+ Test accuracy at epoch 67 is: 96.06
+ Test AUC at epoch 67 is: 98.980
+ Writing kaggle test results in : results/epoch-67-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2252 - accuracy: 0.9211
14/14 [==============================] - 2s 170ms/step - loss: 0.1487 - accuracy: 0.9536
+ Test accuracy at epoch 68 is: 95.36
+ Test AUC at epoch 68 is: 98.560
+ Writing kaggle test results in : results/epoch-68-results.csv...
27/27 - 19s - loss: 0.0833 - accuracy: 0.9721
14/14 [==============================] - 2s 170ms/step - loss: 0.1499 - accuracy: 0.9513
+ Test accuracy at epoch 69 is: 95.13
+ Test AUC at epoch 69 is: 99.040
+ Writing kaggle test results in : results/epoch-69-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2415 - accuracy: 0.9129
14/14 [==============================] - 2s 171ms/step - loss: 0.1678 - accuracy: 0.9350
+ Test accuracy at epoch 70 is: 93.50
+ Test AUC at epoch 70 is: 98.480
+ Writing kaggle test results in : results/epoch-70-results.csv...
27/27 - 19s - loss: 0.0777 - accuracy: 0.9739
14/14 [==============================] - 2s 170ms/step - loss: 0.1823 - accuracy: 0.9327
+ Test accuracy at epoch 71 is: 93.27
+ Test AUC at epoch 71 is: 99.180
+ Writing kaggle test results in : results/epoch-71-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2235 - accuracy: 0.9106
14/14 [==============================] - 2s 170ms/step - loss: 0.1464 - accuracy: 0.9374
+ Test accuracy at epoch 72 is: 93.73
+ Test AUC at epoch 72 is: 98.620
+ Writing kaggle test results in : results/epoch-72-results.csv...
27/27 - 19s - loss: 0.0725 - accuracy: 0.9750
14/14 [==============================] - 2s 171ms/step - loss: 0.2012 - accuracy: 0.9327
+ Test accuracy at epoch 73 is: 93.27
+ Test AUC at epoch 73 is: 98.910
+ Writing kaggle test results in : results/epoch-73-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2136 - accuracy: 0.9193
14/14 [==============================] - 2s 171ms/step - loss: 0.1785 - accuracy: 0.9304
+ Test accuracy at epoch 74 is: 93.04
+ Test AUC at epoch 74 is: 98.240
+ Writing kaggle test results in : results/epoch-74-results.csv...
27/27 - 19s - loss: 0.0690 - accuracy: 0.9774
14/14 [==============================] - 2s 171ms/step - loss: 0.1219 - accuracy: 0.9490
+ Test accuracy at epoch 75 is: 94.90
+ Test AUC at epoch 75 is: 98.940
+ Writing kaggle test results in : results/epoch-75-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2002 - accuracy: 0.9216
14/14 [==============================] - 2s 170ms/step - loss: 0.1719 - accuracy: 0.9420
+ Test accuracy at epoch 76 is: 94.20
+ Test AUC at epoch 76 is: 98.260
+ Writing kaggle test results in : results/epoch-76-results.csv...
27/27 - 19s - loss: 0.0636 - accuracy: 0.9814
14/14 [==============================] - 2s 170ms/step - loss: 0.1290 - accuracy: 0.9443
+ Test accuracy at epoch 77 is: 94.43
+ Test AUC at epoch 77 is: 98.850
+ Writing kaggle test results in : results/epoch-77-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2031 - accuracy: 0.9153
14/14 [==============================] - 2s 170ms/step - loss: 0.3317 - accuracy: 0.8863
+ Test accuracy at epoch 78 is: 88.63
+ Test AUC at epoch 78 is: 98.410
+ Writing kaggle test results in : results/epoch-78-results.csv...
27/27 - 19s - loss: 0.0898 - accuracy: 0.9675
14/14 [==============================] - 2s 170ms/step - loss: 0.3771 - accuracy: 0.8654
+ Test accuracy at epoch 79 is: 86.54
+ Test AUC at epoch 79 is: 98.790
+ Writing kaggle test results in : results/epoch-79-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2407 - accuracy: 0.9106
14/14 [==============================] - 2s 170ms/step - loss: 0.1292 - accuracy: 0.9443
+ Test accuracy at epoch 80 is: 94.43
+ Test AUC at epoch 80 is: 98.910
+ Writing kaggle test results in : results/epoch-80-results.csv...
27/27 - 19s - loss: 0.0702 - accuracy: 0.9779
14/14 [==============================] - 2s 170ms/step - loss: 0.1284 - accuracy: 0.9629
+ Test accuracy at epoch 81 is: 96.29
+ Test AUC at epoch 81 is: 99.180
+ Writing kaggle test results in : results/epoch-81-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2149 - accuracy: 0.9182
14/14 [==============================] - 2s 171ms/step - loss: 0.1327 - accuracy: 0.9582
+ Test accuracy at epoch 82 is: 95.82
+ Test AUC at epoch 82 is: 98.890
+ Writing kaggle test results in : results/epoch-82-results.csv...
27/27 - 19s - loss: 0.0557 - accuracy: 0.9837
14/14 [==============================] - 2s 171ms/step - loss: 0.1172 - accuracy: 0.9513
+ Test accuracy at epoch 83 is: 95.13
+ Test AUC at epoch 83 is: 99.150
+ Writing kaggle test results in : results/epoch-83-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2063 - accuracy: 0.9211
14/14 [==============================] - 2s 170ms/step - loss: 0.1196 - accuracy: 0.9559
+ Test accuracy at epoch 84 is: 95.59
+ Test AUC at epoch 84 is: 98.980
+ Writing kaggle test results in : results/epoch-84-results.csv...
27/27 - 19s - loss: 0.0486 - accuracy: 0.9832
14/14 [==============================] - 2s 171ms/step - loss: 0.1041 - accuracy: 0.9606
+ Test accuracy at epoch 85 is: 96.06
+ Test AUC at epoch 85 is: 99.150
+ Writing kaggle test results in : results/epoch-85-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2196 - accuracy: 0.9141
14/14 [==============================] - 2s 172ms/step - loss: 0.1400 - accuracy: 0.9513
+ Test accuracy at epoch 86 is: 95.13
+ Test AUC at epoch 86 is: 98.800
+ Writing kaggle test results in : results/epoch-86-results.csv...
27/27 - 19s - loss: 0.0534 - accuracy: 0.9826
14/14 [==============================] - 2s 170ms/step - loss: 0.1398 - accuracy: 0.9513
+ Test accuracy at epoch 87 is: 95.13
+ Test AUC at epoch 87 is: 99.170
+ Writing kaggle test results in : results/epoch-87-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.1973 - accuracy: 0.9240
14/14 [==============================] - 2s 171ms/step - loss: 0.1081 - accuracy: 0.9559
+ Test accuracy at epoch 88 is: 95.59
+ Test AUC at epoch 88 is: 99.280
+ Writing kaggle test results in : results/epoch-88-results.csv...
27/27 - 19s - loss: 0.0611 - accuracy: 0.9808
14/14 [==============================] - 2s 170ms/step - loss: 0.1145 - accuracy: 0.9466
+ Test accuracy at epoch 89 is: 94.66
+ Test AUC at epoch 89 is: 99.120
+ Writing kaggle test results in : results/epoch-89-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.1887 - accuracy: 0.9315
14/14 [==============================] - 2s 170ms/step - loss: 0.3254 - accuracy: 0.8770
+ Test accuracy at epoch 90 is: 87.70
+ Test AUC at epoch 90 is: 98.470
+ Writing kaggle test results in : results/epoch-90-results.csv...
27/27 - 19s - loss: 0.0580 - accuracy: 0.9803
14/14 [==============================] - 2s 170ms/step - loss: 0.1328 - accuracy: 0.9466
+ Test accuracy at epoch 91 is: 94.66
+ Test AUC at epoch 91 is: 99.160
+ Writing kaggle test results in : results/epoch-91-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2002 - accuracy: 0.9176
14/14 [==============================] - 2s 170ms/step - loss: 0.1325 - accuracy: 0.9536
+ Test accuracy at epoch 92 is: 95.36
+ Test AUC at epoch 92 is: 98.870
+ Writing kaggle test results in : results/epoch-92-results.csv...
27/27 - 19s - loss: 0.0547 - accuracy: 0.9843
14/14 [==============================] - 2s 170ms/step - loss: 0.1078 - accuracy: 0.9536
+ Test accuracy at epoch 93 is: 95.36
+ Test AUC at epoch 93 is: 99.250
+ Writing kaggle test results in : results/epoch-93-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.1906 - accuracy: 0.9269
14/14 [==============================] - 2s 170ms/step - loss: 0.1293 - accuracy: 0.9466
+ Test accuracy at epoch 94 is: 94.66
+ Test AUC at epoch 94 is: 99.010
+ Writing kaggle test results in : results/epoch-94-results.csv...
27/27 - 19s - loss: 0.0517 - accuracy: 0.9849
14/14 [==============================] - 2s 171ms/step - loss: 0.1280 - accuracy: 0.9420
+ Test accuracy at epoch 95 is: 94.20
+ Test AUC at epoch 95 is: 98.860
+ Writing kaggle test results in : results/epoch-95-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2247 - accuracy: 0.9182
14/14 [==============================] - 2s 171ms/step - loss: 0.1540 - accuracy: 0.9397
+ Test accuracy at epoch 96 is: 93.97
+ Test AUC at epoch 96 is: 99.110
+ Writing kaggle test results in : results/epoch-96-results.csv...
27/27 - 19s - loss: 0.0655 - accuracy: 0.9768
14/14 [==============================] - 2s 170ms/step - loss: 0.0977 - accuracy: 0.9582
+ Test accuracy at epoch 97 is: 95.82
+ Test AUC at epoch 97 is: 99.350
+ Writing kaggle test results in : results/epoch-97-results.csv...
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1969: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
warnings.warn('`Model.fit_generator` is deprecated and '
26/26 - 20s - loss: 0.2047 - accuracy: 0.9205
14/14 [==============================] - 2s 170ms/step - loss: 0.2118 - accuracy: 0.9234
+ Test accuracy at epoch 98 is: 92.34
+ Test AUC at epoch 98 is: 99.160
+ Writing kaggle test results in : results/epoch-98-results.csv...
27/27 - 19s - loss: 0.0436 - accuracy: 0.9855
14/14 [==============================] - 2s 170ms/step - loss: 0.1731 - accuracy: 0.9281
+ Test accuracy at epoch 99 is: 92.81
+ Test AUC at epoch 99 is: 99.090
+ Writing kaggle test results in : results/epoch-99-results.csv...
------------------------------------------------------------------------
*** Printing our best validation results that we obtained in epoch 81 ...
------------------------------------------------------------------------
Accuracy: 96.29
PrecisionNegative: 92.67
PrecisionPositive: 98.22
RecallNegative: 96.53
RecallPositive: 96.17
AUC Score: 99.18
------------------------------------------------------------------------
+ Printing confusion matrix...
+ Printing ROC curve...
################################## You can change values inside the following list ###########################
topNValues = [5, 10, 20, 30,40, 50, 60, 70, 80, 90,100]
##############################################################################################################
accuraciesHealthy, accuraciesPneumonia = [], []
for topn in topNValues:
accuracyHealthy, accuracyPneumonia = calculateClasswiseTopNAccuracy(testLabels, bestAccPredictionProbabilities, topn)
accuraciesHealthy.append(accuracyHealthy)
accuraciesPneumonia.append(accuracyPneumonia)
print("+ Accuracy for top %d percent predictions for healthy: %.2f, pneumonia: %.2f" % (topn, accuracyHealthy, accuracyPneumonia))
# Plot results
x = np.arange(len(accuraciesHealthy))
plt.plot(x, accuraciesHealthy, linewidth = 3, color = '#e01111')
scatterHealthy = plt.scatter(x, accuraciesHealthy, marker = 's', s = 100, color = '#e01111')
plt.plot(x, accuraciesPneumonia, linewidth = 3, color = '#0072ff')
scatterPneumonia = plt.scatter(x, accuraciesPneumonia, marker = 'o', s = 100, color = '#0072ff')
plt.xticks(x, topNValues, fontsize = 15)
plt.yticks(fontsize = 15)
plt.xlabel("Top N%", fontsize = 15)
plt.ylabel("Accuracy", fontsize = 15)
plt.legend([scatterHealthy, scatterPneumonia], ["Accuracy for Healthy", "Accuracy for Pneumonia"], fontsize = 17)
plt.ylim(0, 110)
plt.show()
+ Accuracy for top 5 percent predictions for healthy: 100.00, pneumonia: 100.00
+ Accuracy for top 10 percent predictions for healthy: 100.00, pneumonia: 100.00
+ Accuracy for top 20 percent predictions for healthy: 100.00, pneumonia: 100.00
+ Accuracy for top 30 percent predictions for healthy: 96.09, pneumonia: 100.00
+ Accuracy for top 40 percent predictions for healthy: 92.67, pneumonia: 100.00
+ Accuracy for top 50 percent predictions for healthy: 92.67, pneumonia: 99.53
+ Accuracy for top 60 percent predictions for healthy: 92.67, pneumonia: 99.22
+ Accuracy for top 70 percent predictions for healthy: 92.67, pneumonia: 98.22
+ Accuracy for top 80 percent predictions for healthy: 92.67, pneumonia: 98.22
+ Accuracy for top 90 percent predictions for healthy: 92.67, pneumonia: 98.22
+ Accuracy for top 100 percent predictions for healthy: 92.67, pneumonia: 98.22
print(model.summary())
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 256, 256, 55) 26675
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 85, 85, 55) 0
_________________________________________________________________
dropout (Dropout) (None, 85, 85, 55) 0
_________________________________________________________________
conv2d_1 (Conv2D) (None, 85, 85, 55) 1464155
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 28, 28, 55) 0
_________________________________________________________________
dropout_1 (Dropout) (None, 28, 28, 55) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 28, 28, 55) 1464155
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 9, 9, 55) 0
_________________________________________________________________
dropout_2 (Dropout) (None, 9, 9, 55) 0
_________________________________________________________________
flatten (Flatten) (None, 4455) 0
_________________________________________________________________
dense (Dense) (None, 64) 285184
_________________________________________________________________
batch_normalization (BatchNo (None, 64) 256
_________________________________________________________________
dropout_3 (Dropout) (None, 64) 0
_________________________________________________________________
dense_1 (Dense) (None, 2) 130
=================================================================
Total params: 3,240,555
Trainable params: 3,240,427
Non-trainable params: 128
_________________________________________________________________
None