Question

I'm doing a project where a python script used a convolutional neural network to determine if a plant is healthy, and then water it based on that. While training the CNN, it seems to get up to 100% accuracy quite early, although it isn't accurate. I only have a little less than 2000 images, and was wondering if I didn't have enough, or it was my model, which is here

        self.model = Sequential()
        self.model.add(Conv2D(numFilters, filterSize, activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 3)))
        self.model.add(Conv2D(numFilters * 2, (3, 3), activation='relu'))
        self.model.add(MaxPooling2D(pool_size=poolSize))
        self.model.add(Dropout(0.25))
        self.model.add(Flatten())
        self.model.add(Dense(numFilters * 4, activation='relu'))
        self.model.add(Dropout(0.5))
        self.model.add(Dense(2, activation='softmax'))
        self.model.compile(loss='categorical_crossentropy',
                      optimizer = 'adam',
                      metrics=['accuracy'])

I would just like to know the reason why it doesn't train well. Thanks.

Was it helpful?

Solution

Not sure if your model is too simple, I have used the same number of layers before and had very good results. Guess it depends on many factors, such as the training image dataset, etc. The high accuracy is coming from learning the training data quickly, but the low accuracy means the model you built doesn't apply to the test data, so the model is over-fitting. Some possible causes:

1) not enough training data

2) training images are too similar to each other, but different from the test data

3) model is too complex and does not generalize well 4) etc

Possible fixes:

1) If your training data is too small, you can use public pre-built models (VGGnn, etc) as a starting point. This will work best on models that were built with similar data.

2) If your images are too similar to each other, you can alleviate this by using image augmentation. The keras.preprocessing.image.ImageDataGenerator library is good for this. Here is an example on how to use:

https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

3) If the model is too complex, you can try to simplify by changing filter sizes, or add regularization

OTHER TIPS

First of all, your model looks too simple for the task. 100% accuracy means you might be overfitting on the trainset. 2000 images is not enough to train a model from scratch, use transfer learning. May be try data augmentation as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top