0
$\begingroup$

I am training an image classifier for 7 different model types of a specific car engine parts. Each class has exactly 308 grayscale images with the same resolution of 1014x760. Those images consists mainly of the engine parts on a white screen which got rotated by 60 degrees after each photo take, so the dataset consists of pictures looking mostly very similar to each other. I wanted to train my model for 50 epochs but after the 30th epoch the accuracy reached 1.0 while the validation-accuracy is getting stuck at around 0.2. Why is the result so weird? Could it be that the images are way too similar too each other?

import numpy as np
import pickle
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
from tensorflow.keras.callbacks import TensorBoard
from tensorflow.keras.utils import to_categorical
import time

name = "Core_Classifier_{}".format(int(time.time()))

tensorboard = TensorBoard(log_dir="logs/{}".format(name))

X = pickle.load(open("X.pickle", "rb"))
y = pickle.load(open("y.pickle", "rb"))

X = X/255.0 # normalize color values
y = to_categorical(y, num_classes=7)

model = Sequential()

model.add(Conv2D(64, (3, 3), input_shape = X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))

model.add(Conv2D(64, (3, 3)))
model.add(Activation("relu"))

model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Flatten())

model.add(Dense(64))
model.add(Activation("relu")) # idk if needed

model.add(Dense(7))
model.add(Activation("softmax"))

model.compile(loss = "categorical_crossentropy",
              optimizer = "adam",
              metrics = ["accuracy"])

model.fit(X, y, batch_size = 64, epochs = 50, validation_split = 0.1, callbacks = [tensorboard])

I added 2 model.add(Dropout(0.2)) functions but the result didn't change much.

import numpy as np
import pickle
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
from tensorflow.keras.callbacks import TensorBoard
from tensorflow.keras.utils import to_categorical
import time

name = "Core_Classifier_{}".format(int(time.time()))

tensorboard = TensorBoard(log_dir="logs/{}".format(name))

X = pickle.load(open("X.pickle", "rb"))
y = pickle.load(open("y.pickle", "rb"))

X = X/255.0 # normalize color values
y = to_categorical(y, num_classes=7)

model = Sequential()

model.add(Conv2D(64, (3, 3), input_shape = X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.2))
model.add(Conv2D(64, (3, 3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())

model.add(Dense(64))
model.add(Activation("relu")) # idk if needed

model.add(Dense(7))
model.add(Activation("softmax"))

model.compile(loss = "categorical_crossentropy",
              optimizer = "adam",
              metrics = ["accuracy"])

model.fit(X, y, batch_size = 64, epochs = 50, validation_split = 0.1, callbacks = [tensorboard])

Here is the graph representation via tensorboard
[![enter image description here][1]][1]


  [1]: https://i.sstatic.net/82hjSa3T.png
$\endgroup$
1
  • $\begingroup$ So, basically, your (training?) dataset consists of 308 * 7 images in total. That might not be enough to train the model for your purposes. If you can't collect more images, you could try to augment the dataset by creating more images from the existing ones by e.g. rotating even more the existing ones, blurring, or whatever. Also, how many images are you using for validation or testing? $\endgroup$
    – nbro
    Commented Aug 8 at 11:32

0

You must log in to answer this question.