import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
from keract import display_activations, display_heatmaps, get_activations
train_datagen = ImageDataGenerator(
rotation_range=2,
width_shift_range=0.001,
height_shift_range=0.001,
shear_range=0.001,
zoom_range=[0.99, 1.01],
fill_mode='nearest'
)
valid_datagen = ImageDataGenerator()
size = (500, 700)
train_data_dir = 'data/train'
valid_data_dir = 'data/test'
train_batch_size = 16
valid_batch_size = 8
train_it = train_datagen.flow_from_directory(train_data_dir,
target_size=size,
color_mode='grayscale',
class_mode='categorical',
batch_size=train_batch_size)
valid_it = valid_datagen.flow_from_directory(valid_data_dir,
target_size=size,
color_mode='grayscale',
class_mode='categorical',
batch_size=valid_batch_size)
Found 5232 images belonging to 3 classes. Found 624 images belonging to 3 classes.
data_iter = iter(train_it)
images, labels = next(data_iter)
for ii in range(train_batch_size):
plt.figure()
plt.imshow(images[ii].reshape(size), cmap='gray')
plt.show()
model = keras.Sequential()
model.add(layers.Conv2D(64, (3, 3), activation='relu', input_shape=train_it.image_shape))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((3, 3)))
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((3, 3)))
model.add(layers.Conv2D(256, (3, 3), activation='relu'))
model.add(layers.Conv2D(256, (3, 3), activation='relu'))
model.add(layers.Conv2D(256, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((3, 3)))
model.add(layers.Flatten())
model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(3, activation='softmax'))
model.summary()
Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= conv2d (Conv2D) (None, 498, 698, 64) 640 _________________________________________________________________ conv2d_1 (Conv2D) (None, 496, 696, 64) 36928 _________________________________________________________________ max_pooling2d (MaxPooling2D) (None, 165, 232, 64) 0 _________________________________________________________________ conv2d_2 (Conv2D) (None, 163, 230, 128) 73856 _________________________________________________________________ conv2d_3 (Conv2D) (None, 161, 228, 128) 147584 _________________________________________________________________ max_pooling2d_1 (MaxPooling2 (None, 53, 76, 128) 0 _________________________________________________________________ conv2d_4 (Conv2D) (None, 51, 74, 256) 295168 _________________________________________________________________ conv2d_5 (Conv2D) (None, 49, 72, 256) 590080 _________________________________________________________________ conv2d_6 (Conv2D) (None, 47, 70, 256) 590080 _________________________________________________________________ max_pooling2d_2 (MaxPooling2 (None, 15, 23, 256) 0 _________________________________________________________________ flatten (Flatten) (None, 88320) 0 _________________________________________________________________ dense (Dense) (None, 512) 45220352 _________________________________________________________________ dense_1 (Dense) (None, 64) 32832 _________________________________________________________________ dense_2 (Dense) (None, 3) 195 ================================================================= Total params: 46,987,715 Trainable params: 46,987,715 Non-trainable params: 0 _________________________________________________________________
model.compile(optimizer=keras.optimizers.RMSprop(),
loss=keras.losses.CategoricalCrossentropy(),
metrics=[keras.metrics.CategoricalAccuracy(),
keras.metrics.AUC()
])
callbacks = [
keras.callbacks.ModelCheckpoint(filepath='models/model.{epoch:02d}-{val_loss:.2f}.h5',
monitor='val_auc',
mode='max',
save_weights_only=True,
verbose=1,
save_best_only=True)
]
history = model.fit(train_it,
steps_per_epoch=len(train_it)//train_batch_size,
validation_data=valid_it,
validation_steps=len(valid_it)//valid_batch_size,
epochs=50,
callbacks=callbacks)
Epoch 1/50 20/20 [==============================] - ETA: 0s - loss: 2484.1265 - categorical_accuracy: 0.3313 - auc: 0.5004 Epoch 00001: val_auc improved from -inf to 0.54036, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.01-1.10.h5 20/20 [==============================] - 107s 5s/step - loss: 2484.1265 - categorical_accuracy: 0.3313 - auc: 0.5004 - val_loss: 1.0971 - val_categorical_accuracy: 0.4444 - val_auc: 0.5404 Epoch 2/50 20/20 [==============================] - ETA: 0s - loss: 1.3276 - categorical_accuracy: 0.3688 - auc: 0.5022 Epoch 00002: val_auc improved from 0.54036 to 0.61155, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.02-1.07.h5 20/20 [==============================] - 102s 5s/step - loss: 1.3276 - categorical_accuracy: 0.3688 - auc: 0.5022 - val_loss: 1.0743 - val_categorical_accuracy: 0.2917 - val_auc: 0.6115 Epoch 3/50 20/20 [==============================] - ETA: 0s - loss: 1.8457 - categorical_accuracy: 0.4281 - auc: 0.5813 Epoch 00003: val_auc did not improve from 0.61155 20/20 [==============================] - 94s 5s/step - loss: 1.8457 - categorical_accuracy: 0.4281 - auc: 0.5813 - val_loss: 3.7872 - val_categorical_accuracy: 0.4306 - val_auc: 0.5457 Epoch 4/50 20/20 [==============================] - ETA: 0s - loss: 2.1871 - categorical_accuracy: 0.4656 - auc: 0.5683 Epoch 00004: val_auc did not improve from 0.61155 20/20 [==============================] - 94s 5s/step - loss: 2.1871 - categorical_accuracy: 0.4656 - auc: 0.5683 - val_loss: 1.6162 - val_categorical_accuracy: 0.3611 - val_auc: 0.5170 Epoch 5/50 20/20 [==============================] - ETA: 0s - loss: 2.3866 - categorical_accuracy: 0.4688 - auc: 0.5647 Epoch 00005: val_auc did not improve from 0.61155 20/20 [==============================] - 85s 4s/step - loss: 2.3866 - categorical_accuracy: 0.4688 - auc: 0.5647 - val_loss: 2.5052 - val_categorical_accuracy: 0.3333 - val_auc: 0.4030 Epoch 6/50 20/20 [==============================] - ETA: 0s - loss: 1.5413 - categorical_accuracy: 0.4875 - auc: 0.6468 Epoch 00006: val_auc improved from 0.61155 to 0.65750, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.06-1.18.h5 20/20 [==============================] - 76s 4s/step - loss: 1.5413 - categorical_accuracy: 0.4875 - auc: 0.6468 - val_loss: 1.1829 - val_categorical_accuracy: 0.4306 - val_auc: 0.6575 Epoch 7/50 20/20 [==============================] - ETA: 0s - loss: 3.0699 - categorical_accuracy: 0.4750 - auc: 0.6696 Epoch 00007: val_auc did not improve from 0.65750 20/20 [==============================] - 78s 4s/step - loss: 3.0699 - categorical_accuracy: 0.4750 - auc: 0.6696 - val_loss: 3.5581 - val_categorical_accuracy: 0.3611 - val_auc: 0.5320 Epoch 8/50 20/20 [==============================] - ETA: 0s - loss: 1.1297 - categorical_accuracy: 0.5625 - auc: 0.7338 Epoch 00008: val_auc improved from 0.65750 to 0.77363, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.08-0.95.h5 20/20 [==============================] - 66s 3s/step - loss: 1.1297 - categorical_accuracy: 0.5625 - auc: 0.7338 - val_loss: 0.9536 - val_categorical_accuracy: 0.5972 - val_auc: 0.7736 Epoch 9/50 20/20 [==============================] - ETA: 0s - loss: 1.3624 - categorical_accuracy: 0.5562 - auc: 0.7090 Epoch 00009: val_auc improved from 0.77363 to 0.79360, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.09-0.98.h5 20/20 [==============================] - 63s 3s/step - loss: 1.3624 - categorical_accuracy: 0.5562 - auc: 0.7090 - val_loss: 0.9830 - val_categorical_accuracy: 0.6528 - val_auc: 0.7936 Epoch 10/50 20/20 [==============================] - ETA: 0s - loss: 1.4168 - categorical_accuracy: 0.5719 - auc: 0.7277 Epoch 00010: val_auc improved from 0.79360 to 0.80908, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.10-0.94.h5 20/20 [==============================] - 62s 3s/step - loss: 1.4168 - categorical_accuracy: 0.5719 - auc: 0.7277 - val_loss: 0.9399 - val_categorical_accuracy: 0.6528 - val_auc: 0.8091 Epoch 11/50 20/20 [==============================] - ETA: 0s - loss: 0.9625 - categorical_accuracy: 0.6156 - auc: 0.7717 Epoch 00011: val_auc improved from 0.80908 to 0.85692, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.11-1.08.h5 20/20 [==============================] - 58s 3s/step - loss: 0.9625 - categorical_accuracy: 0.6156 - auc: 0.7717 - val_loss: 1.0754 - val_categorical_accuracy: 0.7639 - val_auc: 0.8569 Epoch 12/50 20/20 [==============================] - ETA: 0s - loss: 1.3073 - categorical_accuracy: 0.5688 - auc: 0.7334 Epoch 00012: val_auc did not improve from 0.85692 20/20 [==============================] - 52s 3s/step - loss: 1.3073 - categorical_accuracy: 0.5688 - auc: 0.7334 - val_loss: 0.8795 - val_categorical_accuracy: 0.6806 - val_auc: 0.8547 Epoch 13/50 20/20 [==============================] - ETA: 0s - loss: 1.7169 - categorical_accuracy: 0.6062 - auc: 0.7527 Epoch 00013: val_auc improved from 0.85692 to 0.90818, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.13-0.76.h5 20/20 [==============================] - 52s 3s/step - loss: 1.7169 - categorical_accuracy: 0.6062 - auc: 0.7527 - val_loss: 0.7574 - val_categorical_accuracy: 0.7917 - val_auc: 0.9082 Epoch 14/50 20/20 [==============================] - ETA: 0s - loss: 0.8807 - categorical_accuracy: 0.6344 - auc: 0.8021 Epoch 00014: val_auc did not improve from 0.90818 20/20 [==============================] - 50s 2s/step - loss: 0.8807 - categorical_accuracy: 0.6344 - auc: 0.8021 - val_loss: 1.4626 - val_categorical_accuracy: 0.5139 - val_auc: 0.6798 Epoch 15/50 20/20 [==============================] - ETA: 0s - loss: 1.3377 - categorical_accuracy: 0.6156 - auc: 0.7602 Epoch 00015: val_auc did not improve from 0.90818 20/20 [==============================] - 46s 2s/step - loss: 1.3377 - categorical_accuracy: 0.6156 - auc: 0.7602 - val_loss: 0.8187 - val_categorical_accuracy: 0.7361 - val_auc: 0.8411 Epoch 16/50 20/20 [==============================] - ETA: 0s - loss: 0.8000 - categorical_accuracy: 0.6844 - auc: 0.8297 Epoch 00016: val_auc did not improve from 0.90818 20/20 [==============================] - 42s 2s/step - loss: 0.8000 - categorical_accuracy: 0.6844 - auc: 0.8297 - val_loss: 0.9128 - val_categorical_accuracy: 0.6667 - val_auc: 0.8817 Epoch 17/50 20/20 [==============================] - ETA: 0s - loss: 0.8147 - categorical_accuracy: 0.6250 - auc: 0.8333 Epoch 00017: val_auc did not improve from 0.90818 20/20 [==============================] - 46s 2s/step - loss: 0.8147 - categorical_accuracy: 0.6250 - auc: 0.8333 - val_loss: 1.3545 - val_categorical_accuracy: 0.7500 - val_auc: 0.8542 Epoch 18/50 20/20 [==============================] - ETA: 0s - loss: 1.2946 - categorical_accuracy: 0.5969 - auc: 0.7779 Epoch 00018: val_auc did not improve from 0.90818 20/20 [==============================] - 44s 2s/step - loss: 1.2946 - categorical_accuracy: 0.5969 - auc: 0.7779 - val_loss: 1.9045 - val_categorical_accuracy: 0.5139 - val_auc: 0.7373 Epoch 19/50 20/20 [==============================] - ETA: 0s - loss: 0.9210 - categorical_accuracy: 0.6344 - auc: 0.8090 Epoch 00019: val_auc did not improve from 0.90818 20/20 [==============================] - 40s 2s/step - loss: 0.9210 - categorical_accuracy: 0.6344 - auc: 0.8090 - val_loss: 1.2419 - val_categorical_accuracy: 0.6389 - val_auc: 0.7978 Epoch 20/50 20/20 [==============================] - ETA: 0s - loss: 0.8128 - categorical_accuracy: 0.6562 - auc: 0.8186 Epoch 00020: val_auc did not improve from 0.90818 20/20 [==============================] - 31s 2s/step - loss: 0.8128 - categorical_accuracy: 0.6562 - auc: 0.8186 - val_loss: 1.0361 - val_categorical_accuracy: 0.7222 - val_auc: 0.8387 Epoch 21/50 20/20 [==============================] - ETA: 0s - loss: 1.2822 - categorical_accuracy: 0.6250 - auc: 0.7822 Epoch 00021: val_auc did not improve from 0.90818 20/20 [==============================] - 32s 2s/step - loss: 1.2822 - categorical_accuracy: 0.6250 - auc: 0.7822 - val_loss: 3.2290 - val_categorical_accuracy: 0.6111 - val_auc: 0.7370 Epoch 22/50 20/20 [==============================] - ETA: 0s - loss: 1.7835 - categorical_accuracy: 0.6344 - auc: 0.7732 Epoch 00022: val_auc did not improve from 0.90818 20/20 [==============================] - 31s 2s/step - loss: 1.7835 - categorical_accuracy: 0.6344 - auc: 0.7732 - val_loss: 0.7701 - val_categorical_accuracy: 0.7500 - val_auc: 0.8736 Epoch 23/50 20/20 [==============================] - ETA: 0s - loss: 1.1893 - categorical_accuracy: 0.6562 - auc: 0.8129 Epoch 00023: val_auc did not improve from 0.90818 20/20 [==============================] - 32s 2s/step - loss: 1.1893 - categorical_accuracy: 0.6562 - auc: 0.8129 - val_loss: 5.7681 - val_categorical_accuracy: 0.2500 - val_auc: 0.4571 Epoch 24/50 20/20 [==============================] - ETA: 0s - loss: 1.0706 - categorical_accuracy: 0.6250 - auc: 0.7826 Epoch 00024: val_auc did not improve from 0.90818 20/20 [==============================] - 33s 2s/step - loss: 1.0706 - categorical_accuracy: 0.6250 - auc: 0.7826 - val_loss: 1.1160 - val_categorical_accuracy: 0.7500 - val_auc: 0.8621 Epoch 25/50 20/20 [==============================] - ETA: 0s - loss: 0.7494 - categorical_accuracy: 0.6812 - auc: 0.8492 Epoch 00025: val_auc did not improve from 0.90818 20/20 [==============================] - 27s 1s/step - loss: 0.7494 - categorical_accuracy: 0.6812 - auc: 0.8492 - val_loss: 1.0130 - val_categorical_accuracy: 0.5972 - val_auc: 0.8241 Epoch 26/50 20/20 [==============================] - ETA: 0s - loss: 0.8402 - categorical_accuracy: 0.6500 - auc: 0.8169 Epoch 00026: val_auc did not improve from 0.90818 20/20 [==============================] - 30s 1s/step - loss: 0.8402 - categorical_accuracy: 0.6500 - auc: 0.8169 - val_loss: 1.0745 - val_categorical_accuracy: 0.5972 - val_auc: 0.8168 Epoch 27/50 20/20 [==============================] - ETA: 0s - loss: 0.8163 - categorical_accuracy: 0.6844 - auc: 0.8478 Epoch 00027: val_auc did not improve from 0.90818 20/20 [==============================] - 26s 1s/step - loss: 0.8163 - categorical_accuracy: 0.6844 - auc: 0.8478 - val_loss: 1.7340 - val_categorical_accuracy: 0.6944 - val_auc: 0.8344 Epoch 28/50 20/20 [==============================] - ETA: 0s - loss: 0.8036 - categorical_accuracy: 0.7125 - auc: 0.8536 Epoch 00028: val_auc did not improve from 0.90818 20/20 [==============================] - 28s 1s/step - loss: 0.8036 - categorical_accuracy: 0.7125 - auc: 0.8536 - val_loss: 1.2284 - val_categorical_accuracy: 0.7222 - val_auc: 0.8073 Epoch 29/50 20/20 [==============================] - ETA: 0s - loss: 0.7278 - categorical_accuracy: 0.6719 - auc: 0.8528 Epoch 00029: val_auc did not improve from 0.90818 20/20 [==============================] - 24s 1s/step - loss: 0.7278 - categorical_accuracy: 0.6719 - auc: 0.8528 - val_loss: 0.8924 - val_categorical_accuracy: 0.6944 - val_auc: 0.8700 Epoch 30/50 20/20 [==============================] - ETA: 0s - loss: 1.9785 - categorical_accuracy: 0.7156 - auc: 0.8564 Epoch 00030: val_auc did not improve from 0.90818 20/20 [==============================] - 25s 1s/step - loss: 1.9785 - categorical_accuracy: 0.7156 - auc: 0.8564 - val_loss: 0.9921 - val_categorical_accuracy: 0.7917 - val_auc: 0.8838 Epoch 31/50 20/20 [==============================] - ETA: 0s - loss: 0.7584 - categorical_accuracy: 0.7156 - auc: 0.8611 Epoch 00031: val_auc did not improve from 0.90818 20/20 [==============================] - 21s 1s/step - loss: 0.7584 - categorical_accuracy: 0.7156 - auc: 0.8611 - val_loss: 1.9118 - val_categorical_accuracy: 0.6806 - val_auc: 0.7979 Epoch 32/50 20/20 [==============================] - ETA: 0s - loss: 0.6157 - categorical_accuracy: 0.7688 - auc: 0.9008 Epoch 00032: val_auc did not improve from 0.90818 20/20 [==============================] - 24s 1s/step - loss: 0.6157 - categorical_accuracy: 0.7688 - auc: 0.9008 - val_loss: 21.2469 - val_categorical_accuracy: 0.1944 - val_auc: 0.4080 Epoch 33/50 20/20 [==============================] - ETA: 0s - loss: 1.2352 - categorical_accuracy: 0.7219 - auc: 0.8571 Epoch 00033: val_auc did not improve from 0.90818 20/20 [==============================] - 24s 1s/step - loss: 1.2352 - categorical_accuracy: 0.7219 - auc: 0.8571 - val_loss: 0.9117 - val_categorical_accuracy: 0.7778 - val_auc: 0.8724 Epoch 34/50 20/20 [==============================] - ETA: 0s - loss: 0.7483 - categorical_accuracy: 0.7625 - auc: 0.8934 Epoch 00034: val_auc did not improve from 0.90818 20/20 [==============================] - 23s 1s/step - loss: 0.7483 - categorical_accuracy: 0.7625 - auc: 0.8934 - val_loss: 1.1882 - val_categorical_accuracy: 0.7083 - val_auc: 0.8378 Epoch 35/50 20/20 [==============================] - ETA: 0s - loss: 0.8280 - categorical_accuracy: 0.7312 - auc: 0.8662 Epoch 00035: val_auc did not improve from 0.90818 20/20 [==============================] - 22s 1s/step - loss: 0.8280 - categorical_accuracy: 0.7312 - auc: 0.8662 - val_loss: 1.0274 - val_categorical_accuracy: 0.6944 - val_auc: 0.8668 Epoch 36/50 20/20 [==============================] - ETA: 0s - loss: 0.6602 - categorical_accuracy: 0.7250 - auc: 0.8782 Epoch 00036: val_auc did not improve from 0.90818 20/20 [==============================] - 19s 938ms/step - loss: 0.6602 - categorical_accuracy: 0.7250 - auc: 0.8782 - val_loss: 1.1051 - val_categorical_accuracy: 0.6389 - val_auc: 0.8288 Epoch 37/50 20/20 [==============================] - ETA: 0s - loss: 0.8121 - categorical_accuracy: 0.6594 - auc: 0.8266 Epoch 00037: val_auc did not improve from 0.90818 20/20 [==============================] - 19s 941ms/step - loss: 0.8121 - categorical_accuracy: 0.6594 - auc: 0.8266 - val_loss: 0.9487 - val_categorical_accuracy: 0.7639 - val_auc: 0.8717 Epoch 38/50 20/20 [==============================] - ETA: 0s - loss: 0.9182 - categorical_accuracy: 0.6812 - auc: 0.8349 Epoch 00038: val_auc did not improve from 0.90818 20/20 [==============================] - 20s 1s/step - loss: 0.9182 - categorical_accuracy: 0.6812 - auc: 0.8349 - val_loss: 1.1956 - val_categorical_accuracy: 0.7639 - val_auc: 0.8731 Epoch 39/50 20/20 [==============================] - ETA: 0s - loss: 2.4604 - categorical_accuracy: 0.6875 - auc: 0.8432 Epoch 00039: val_auc improved from 0.90818 to 0.92959, saving model to /content/drive/MyDrive/Colab Notebooks/PneumoniaDetectionDeepLearning/models/model.39-0.54.h5 20/20 [==============================] - 21s 1s/step - loss: 2.4604 - categorical_accuracy: 0.6875 - auc: 0.8432 - val_loss: 0.5416 - val_categorical_accuracy: 0.8333 - val_auc: 0.9296 Epoch 40/50 20/20 [==============================] - ETA: 0s - loss: 0.7816 - categorical_accuracy: 0.6875 - auc: 0.8561 Epoch 00040: val_auc did not improve from 0.92959 20/20 [==============================] - 22s 1s/step - loss: 0.7816 - categorical_accuracy: 0.6875 - auc: 0.8561 - val_loss: 0.9629 - val_categorical_accuracy: 0.8056 - val_auc: 0.8825 Epoch 41/50 20/20 [==============================] - ETA: 0s - loss: 0.6838 - categorical_accuracy: 0.7437 - auc: 0.8884 Epoch 00041: val_auc did not improve from 0.92959 20/20 [==============================] - 19s 944ms/step - loss: 0.6838 - categorical_accuracy: 0.7437 - auc: 0.8884 - val_loss: 1.0902 - val_categorical_accuracy: 0.5556 - val_auc: 0.7586 Epoch 42/50 20/20 [==============================] - ETA: 0s - loss: 0.7073 - categorical_accuracy: 0.7219 - auc: 0.8694 Epoch 00042: val_auc did not improve from 0.92959 20/20 [==============================] - 19s 974ms/step - loss: 0.7073 - categorical_accuracy: 0.7219 - auc: 0.8694 - val_loss: 1.0541 - val_categorical_accuracy: 0.6528 - val_auc: 0.8223 Epoch 43/50 20/20 [==============================] - ETA: 0s - loss: 0.7335 - categorical_accuracy: 0.7219 - auc: 0.8772 Epoch 00043: val_auc did not improve from 0.92959 20/20 [==============================] - 23s 1s/step - loss: 0.7335 - categorical_accuracy: 0.7219 - auc: 0.8772 - val_loss: 1.2231 - val_categorical_accuracy: 0.7083 - val_auc: 0.8072 Epoch 44/50 20/20 [==============================] - ETA: 0s - loss: 0.8148 - categorical_accuracy: 0.7219 - auc: 0.8611 Epoch 00044: val_auc did not improve from 0.92959 20/20 [==============================] - 17s 854ms/step - loss: 0.8148 - categorical_accuracy: 0.7219 - auc: 0.8611 - val_loss: 0.7469 - val_categorical_accuracy: 0.8194 - val_auc: 0.9198 Epoch 45/50 20/20 [==============================] - ETA: 0s - loss: 0.6654 - categorical_accuracy: 0.7406 - auc: 0.8856 Epoch 00045: val_auc did not improve from 0.92959 20/20 [==============================] - 16s 822ms/step - loss: 0.6654 - categorical_accuracy: 0.7406 - auc: 0.8856 - val_loss: 0.9139 - val_categorical_accuracy: 0.7083 - val_auc: 0.8773 Epoch 46/50 20/20 [==============================] - ETA: 0s - loss: 0.6649 - categorical_accuracy: 0.7500 - auc: 0.8905 Epoch 00046: val_auc did not improve from 0.92959 20/20 [==============================] - 17s 837ms/step - loss: 0.6649 - categorical_accuracy: 0.7500 - auc: 0.8905 - val_loss: 1.2410 - val_categorical_accuracy: 0.7222 - val_auc: 0.8882 Epoch 47/50 20/20 [==============================] - ETA: 0s - loss: 0.7412 - categorical_accuracy: 0.6875 - auc: 0.8654 Epoch 00047: val_auc did not improve from 0.92959 20/20 [==============================] - 15s 775ms/step - loss: 0.7412 - categorical_accuracy: 0.6875 - auc: 0.8654 - val_loss: 1.8869 - val_categorical_accuracy: 0.7083 - val_auc: 0.8329 Epoch 48/50 20/20 [==============================] - ETA: 0s - loss: 0.6596 - categorical_accuracy: 0.7281 - auc: 0.8798 Epoch 00048: val_auc did not improve from 0.92959 20/20 [==============================] - 17s 838ms/step - loss: 0.6596 - categorical_accuracy: 0.7281 - auc: 0.8798 - val_loss: 0.8055 - val_categorical_accuracy: 0.7500 - val_auc: 0.8810 Epoch 49/50 20/20 [==============================] - ETA: 0s - loss: 0.9375 - categorical_accuracy: 0.7344 - auc: 0.8550 Epoch 00049: val_auc did not improve from 0.92959 20/20 [==============================] - 20s 991ms/step - loss: 0.9375 - categorical_accuracy: 0.7344 - auc: 0.8550 - val_loss: 1.0532 - val_categorical_accuracy: 0.7222 - val_auc: 0.8576 Epoch 50/50 20/20 [==============================] - ETA: 0s - loss: 0.6293 - categorical_accuracy: 0.7437 - auc: 0.9071 Epoch 00050: val_auc did not improve from 0.92959 20/20 [==============================] - 16s 821ms/step - loss: 0.6293 - categorical_accuracy: 0.7437 - auc: 0.9071 - val_loss: 1.2485 - val_categorical_accuracy: 0.7361 - val_auc: 0.8269
plt.plot(history.history['categorical_accuracy'])
plt.plot(history.history['val_categorical_accuracy'])
plt.title('Model Performance')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'val'], loc='upper left')
plt.show()
a = get_activations(model, images[0].reshape((1,size[0],size[1],1)))
display_activations(a)
conv2d_input (1, 500, 700, 1)
conv2d (1, 498, 698, 64)
conv2d_1 (1, 496, 696, 64)
max_pooling2d (1, 165, 232, 64)
conv2d_2 (1, 163, 230, 128)
conv2d_3 (1, 161, 228, 128)
max_pooling2d_1 (1, 53, 76, 128)
conv2d_4 (1, 51, 74, 256)
conv2d_5 (1, 49, 72, 256)
conv2d_6 (1, 47, 70, 256)
max_pooling2d_2 (1, 15, 23, 256)
flatten (1, 88320)
dense (1, 512)
dense_1 (1, 64)
dense_2 (1, 3)
display_heatmaps(a, images[0].reshape((1,size[0],size[1],1)))
conv2d_input (1, 500, 700, 1)
conv2d (1, 498, 698, 64)
conv2d_1 (1, 496, 696, 64)
max_pooling2d (1, 165, 232, 64)
conv2d_2 (1, 163, 230, 128)
conv2d_3 (1, 161, 228, 128)
max_pooling2d_1 (1, 53, 76, 128)
conv2d_4 (1, 51, 74, 256)
conv2d_5 (1, 49, 72, 256)
conv2d_6 (1, 47, 70, 256)
max_pooling2d_2 (1, 15, 23, 256)
flatten (1, 88320) -> Skipped. 2D Activations. dense (1, 512) -> Skipped. 2D Activations. dense_1 (1, 64) -> Skipped. 2D Activations. dense_2 (1, 3) -> Skipped. 2D Activations.