Title: CNN with Tensorflow, Keras | Accuracy not improving at all
Tags: python,keras,conv-neural-network

Question: I have a deep learning model for multi-label image classification using Convolutional Neural Networks (CNN) in Python. Despite trying various combinations, the accuracy of my model only reaches up to 30%. Can anyone offer any suggestions on how to improve the accuracy of my model?
def baseline_model_1():
    model = Sequential()
    model.add(Conv2D(filters=32, kernel_size=(3, 3), activation="relu", kernel_regularizer=regularizers.l1_l2(1e-4,1e-4), input_shape=(height,weight,3)))
    model.add(Conv2D(filters=32, kernel_size=(3, 3), activation="relu", kernel_regularizer=regularizers.l1_l2(1e-4,1e-4)))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(BatchNormalization())
    model.add(Dropout(0.5))
    model.add(Conv2D(filters=64, kernel_size=(3, 3), activation='relu', kernel_regularizer=regularizers.l1_l2(1e-4,1e-4)))
    model.add(Conv2D(filters=64, kernel_size=(3, 3), activation='relu', kernel_regularizer=regularizers.l1_l2(1e-4,1e-4)))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(BatchNormalization())
    model.add(Dropout(0.5))
    model.add(Conv2D(filters=86, kernel_size=(3, 3), activation="relu", kernel_regularizer=regularizers.l1_l2(1e-4,1e-4)))
    model.add(Conv2D(filters=86, kernel_size=(3, 3), activation="relu", kernel_regularizer=regularizers.l1_l2(1e-4,1e-4)))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(BatchNormalization())
    model.add(Dropout(0.5))
    model.add(Conv2D(filters=128, kernel_size=(5, 5), activation='relu', kernel_regularizer=regularizers.l1_l2(1e-4,1e-4)))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(BatchNormalization())
    model.add(Dropout(0.5))
    model.add(Flatten())
    model.add(Dense(512, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(6, activation='softmax'))
    model.compile(optimizer=tf.keras.optimizers.SGD(), loss='categorical_crossentropy', metrics=['accuracy'])

    return model

My image datagenerators looks like this
train_dataset = train_datagen.flow_from_dataframe(
    df_train,
    directory = directory_path_train,
    x_col = "image",
    y_col = "labels",
    target_size = (height, weight),
    class_mode = 'categorical',
    batch_size = bat_size,
    subset = "training",
    shuffle = True,
    seed = 1234,
    validate_filenames = False
)
validation_dataset = train_datagen.flow_from_dataframe(
    df_train,
    directory = directory_path_train,
    x_col = "image",
    y_col = "labels",
    target_size = (height, weight),
    class_mode='categorical',
    batch_size = bat_size,
    subset = "validation",
    shuffle = True,
    seed = 1234,
    validate_filenames = False
)
test_dataset = test_datagen.flow_from_dataframe(
    df_test,
    directory = directory_path_test,
    x_col = 'image',
    y_col = None,
    class_mode = None,
    target_size = (height, weight)
)

This is the output of it.
Found 14906 non-validated image filenames belonging to 6 classes.
Found 3726 non-validated image filenames belonging to 6 classes.
Found 3 validated image filenames.

Answer: Have you tried with "ADAM" optimizer? That won't be the issue, but it could improve the score. Also look into if the model is overfitting or not. If that's the case then lower your learning_rate. Also try using different batch_size. Also try with early stopping.