Reputation: 33
I've reached 71% accuracy with my model, however it almost always just labels the picture as a "dog" (~67% pictures are dogs). My training dataset contains 3680 pictures, and the testing one contains 3670 pictures.
model = Sequential()
model.add(Conv2D(filters=64, kernel_size=(3, 3),activation='relu', padding="same", input_shape=input_shape))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2)))
model.add(Dropout(0.2))
model.add(Conv2D(filters=128, kernel_size=(3, 3),activation='relu', padding="same"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2)))
model.add(Dropout(0.25))
model.add(Conv2D(filters=256, kernel_size=(3, 3),activation='relu', padding="same"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2)))
model.add(Dropout(0.3))
model.add(Conv2D(filters=512, kernel_size=(3, 3),activation='relu', padding="same"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2)))
model.add(Dropout(0.35))
model.add(Conv2D(filters=512, kernel_size=(3, 3),activation='relu', padding="same"))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2)))
model.add(Dropout(0.4))
model.add(Flatten())
model.add(Dense(4096, activation='relu'))
model.add(Dense(4096, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))
I am resizing the pictures to 200x200 squares and shuffling the data before training. I have set it on 64 batch-size and 60 epochs (~7 hours of training). I am using Adam optimizer with learning rate = 0.001 (increasing the lr causes overfitting). Should I shrink my testing set? Do I have too much dropout? Are my parameters alright?
Upvotes: 1
Views: 409
Reputation: 301
Your parameters are fine, but you are feeding the NN 200x200 images, which could cause some under fitting (ie: the NN is getting fed too much data at once and is performing poorly due to it).
To fix this, try making the images a size more like 50x50 which should speed up training significantly. You can do this with a simple python script using the glob and PIL libraries which should by default should be installed. If PIL is not installed, run pip install Pillow
, which should install it.
You could also try converting them to black and white with numpy.
Upvotes: 1
Reputation: 453
If you take a look at towards data science page there are some good examples of architectures of neural networks that you can use to improve your model. For example you can use ResNet like structures with residuals training or you can use Inception like networks with different Conv2D kernel sizes merging together. This allows to extract "different size" features using different kernels and merging the information together. Also I suggest you change your activation from "relu" to "selu" to avoid neurons death and to add some non-linearity. And also take a look at SeparableConv2D layers. They help to speed up a lot the training and can improve performance if used in the right way.
Also suggest to leave the dropout layers "at the end" of the model, so you let the first layers to learn features and use the last layers to account for generalisation and avoid overfitting.
Upvotes: 1