0
$\begingroup$

its my first time posting here. I'm trying to build a CNN model that identifies fruits from a dataset of apples, bananas, mixed fruits, and oranges. So far, one of the things I have done to prevent overfitting is to augmented the training data to increase the size of the training dataset. I've tested the model and though the performance with the test data seemed fine, I think I might be overfitting the model but I'm not sure.

Here is my code:

model64 = tf.keras.Sequential()

#Architecture
model64.add(tf.keras.layers.Conv2D(filters = 32,
                                 kernel_size = (3, 3),
                                 activation = "relu",
                                 input_shape = (64, 64, 3)))

model64.add(tf.keras.layers.Conv2D(filters = 32,
                                 kernel_size = (3, 3),
                                 activation = "relu"))

model64.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))

model64.add(tf.keras.layers.Dropout(rate=0.5))

model64.add(tf.keras.layers.Flatten())

model64.add(tf.keras.layers.Dropout(rate=0.5))

model64.add(tf.keras.layers.Dense(units=128, activation='relu'))

model64.add(tf.keras.layers.Dropout(rate=0.5))

#output layer
model64.add(tf.keras.layers.Dense(units=4, activation='softmax'))

#Loss function
model64.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

callback = tf.keras.callbacks.EarlyStopping(monitor='loss', patience=3)

#Train model
hist64 = model64.fit(datagen.flow(x=x_train64_norm, y=y_train), epochs=250)

#Test and Evaluate
print("Performance with test data:")
loss64, accuracy64 = model64.evaluate(x=x_test64_norm, y=y_test)
print('loss =', loss64)
print('accuracy =', accuracy64)

The performance with the test data is

Loss = 0.1860
Accuracy = 0.9333

However, my loss curve seem to be indicating that it is overfitted: Loss Curve and Accuracy Curve

If the model is still overfitted, what else can I do to reduce overfitting?

Thank you for any suggestion!

New contributor
Code Learner is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
1
  • $\begingroup$ Seeing just the loss/accuracy on the test dataset it is impossible to say if your model is overfitting. When checking for overfitting you always compare the loss/accuracy between the training and test dataset. $\endgroup$
    – Oxbowerce
    Nov 25 at 8:36

Your Answer

Code Learner is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.