Search code examples
pythontensorflowkerasdeep-learningneural-network

keras model makes very inaccurate predictions


I never worked with KI before and recently got a task to make a model which can predict two specific rooms in an building and outdoor asap. -.-

For learning and testing I created an dataset with three classes: bedroom, kitchen, outdoor and tried to create a model with it (~14k pictures each).

With my non-existing knowhow I think I already got pretty far but I have a few problems I can't get my head around.

At first the model predicted always the same: the last class got always 100%. Now I'm pretty sure it was a problem with the model definition and changed it.

Now the model gets a few prediction right, but most of them are still wrong... And as far as I understand the training and validation accuracy ratio is also pretty bad.

I hope someone can help me and bring me on the right path :D

BTW if you now how to infuse the label names into the model so thats easy to know them when deploying the model on another device is easy, please tell me ;)

Jupyter Notebook

Current Model

# ----- Define Keras Model -----
model = Sequential([
    layers.Rescaling(1./255, input_shape=(IMAGE_HEIGHT, IMAGE_WIDTH, 3)),
    layers.Conv2D(64, (3, 3), activation = 'relu'),
    layers.MaxPooling2D(2, 2),
    layers.Conv2D(64, (3, 3), activation = 'relu'),
    layers.MaxPooling2D(2, 2),
    layers.Conv2D(64, (3, 3), activation = 'relu'),
    layers.MaxPooling2D(2, 2),
    layers.Flatten(),
    # tf.keras.layers.Dropout(0.2),
    layers.Dense(128, activation = 'relu'),
    layers.Dense(len(class_names), activation = 'softmax')
])

Accuracy of current model


Solution

  • Your model looks too lightweight for the task. Try increasing number of convolutional-maxpool blocks from 2 to 5-6, convolutional filters from 32 to 64. Also, increase number of training epochs to 10-20. This should improve accuracy.