I have a binary classification problem with a small dataset of thermal images, detecting if an image has a human or not.
my data shapes are like this:
print('Train: X_train_images=%s, y_train_labels=%s' % (X_train_images.shape, y_train_labels.shape))
print('Validation: X_val_images=%s, y_val_labels=%s' % (X_val_images.shape, y_val_labels.shape))
Train: X_train_images=(3932, 100, 100, 3), y_train_labels=(3932, 1)
Validation: X_val_images=(800, 100, 100, 3), y_val_labels=(800, 1)
so I have set an input shape as
input_shape = X_train_images.shape[1:]
# (100, 100, 3)
and my model like this:
model_cnn = tf.keras.Sequential([
Conv2D(100, (3,3), padding = 'SAME', activation = 'relu', input_shape =(input_shape)),
Conv2D(60, (3,3), padding = 'SAME', activation = 'relu', input_shape =(input_shape)),
MaxPooling2D(2,2),
Conv2D(30, (3,3), padding = 'SAME', activation = 'relu', input_shape =(input_shape)),
Conv2D(20, (3,3), padding = 'SAME', activation = 'relu', input_shape =(input_shape)),
MaxPooling2D(2,2),
Flatten(),
Dense(20, activation = 'relu'),
Dense(1, activation = "sigmoid"),
])
model_cnn.summary()
Model: "sequential_3"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_13 (Conv2D) (None, 100, 100, 100) 2800
_________________________________________________________________
conv2d_14 (Conv2D) (None, 100, 100, 60) 54060
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 50, 50, 60) 0
_________________________________________________________________
conv2d_15 (Conv2D) (None, 50, 50, 30) 16230
_________________________________________________________________
conv2d_16 (Conv2D) (None, 50, 50, 20) 5420
_________________________________________________________________
max_pooling2d_7 (MaxPooling2 (None, 25, 25, 20) 0
_________________________________________________________________
flatten_3 (Flatten) (None, 12500) 0
_________________________________________________________________
dense_6 (Dense) (None, 20) 250020
_________________________________________________________________
dense_7 (Dense) (None, 1) 21
=================================================================
Total params: 328,551
Trainable params: 328,551
Non-trainable params: 0
cnn_model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
Yet I am not sure if this is the best architecture for the problem at hand?
My accuracy on the validation set and the test set, is 71.9% and 95.3%, respectively.
Here is my validation accuracy and loss plots.
Shall I add more convolutional layers, regularisation layers (dropout() etc) ?
Is it OK to add them after the convolutional layers like so?
Model: "sequential_5"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_21 (Conv2D) (None, 100, 100, 100) 2800
_________________________________________________________________
dropout_3 (Dropout) (None, 100, 100, 100) 0
_________________________________________________________________
conv2d_22 (Conv2D) (None, 100, 100, 60) 54060
_________________________________________________________________
dropout_4 (Dropout) (None, 100, 100, 60) 0
_________________________________________________________________
max_pooling2d_10 (MaxPooling (None, 50, 50, 60) 0
_________________________________________________________________
conv2d_23 (Conv2D) (None, 50, 50, 30) 16230
_________________________________________________________________
dropout_5 (Dropout) (None, 50, 50, 30) 0
_________________________________________________________________
conv2d_24 (Conv2D) (None, 50, 50, 20) 5420
_________________________________________________________________
max_pooling2d_11 (MaxPooling (None, 25, 25, 20) 0
_________________________________________________________________
flatten_5 (Flatten) (None, 12500) 0
_________________________________________________________________
dense_10 (Dense) (None, 20) 250020
_________________________________________________________________
dense_11 (Dense) (None, 1) 21
=================================================================
Total params: 328,551
Trainable params: 328,551
Non-trainable params: 0
I am also not sure if I should be increasing input dimensions? my original image dimensions were 300 x 400 pixels, and I have loaded them as a 100 x 100 x 3 tensor via a manually defined function.
I have posted a separate question on dimensions.
Thank you very much for any advice on how to improve my model