Can't prevent CNN model from overfitting by reducing layers, increasing Dropout or increasing learning rate

55 views Asked by At

I want to make an image classifier using CNN. There are two types of images in the dataset: men and women. in total there are 2300 images, 20% of which I used for validation. the problem is that my model isn't good at all because of overfitting(I think that's the problem) but I cant figure out why my model overfits so badly(please open the link of the graph below. maximum value of y is 3.5) here's the keras model I used to make bicategorical predictions

early_stopping = EarlyStopping(min_delta = 0.001, patience = 20, restore_best_weights = True)
model = tf.keras.Sequential()   
model.add(tf.keras.layers.Conv2D(64, (3, 3), activation = 'relu'))  
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Conv2D(64, (3, 3), activation = 'relu'))  
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(32, activation = 'relu'))
model.add(tf.keras.layers.Dropout(0.25))
model.add(tf.keras.layers.Dense(32, activation = 'relu'))
model.add(tf.keras.layers.Dropout(0.25))
model.add(tf.keras.layers.Dense(2, activation = 'softmax'))
opt = keras.optimizers.Adam(learning_rate=0.01)
model.compile(optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy']) 
history = model.fit(xtrain, ytrain, validation_data = (xval, yval), batch_size = 16, epochs = 100, callbacks = [early_stopping], verbose = 0)

I usually get this kind of results

0

There are 0 answers