Reputation: 95
I have 4 different types of images like bicyle,car,airplane and musicalinstrument and i tried to make image classification with this dataset.Then when i train the model i get this accuracy : 0.62 What should i do to increase the accuracy?
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D
from keras.optimizers import RMSprop,Adam
#build the model
#set up the layers
model = Sequential()
model.add(Conv2D(filters = 8, kernel_size = (5,5),padding = 'Same',
activation ='relu', input_shape = (IMG_SIZE,IMG_SIZE,1)))
model.add(MaxPool2D(pool_size=(2,2)))
model.add(Dropout(0.25))
model.add(Conv2D(filters = 16, kernel_size = (3,3),padding = 'Same',
activation ='relu'))
model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation = "softmax"))
# Define the optimizer
#Adam optimizer: Change the learning rate
optimizer = Adam(lr=0.001, beta_1=0.9, beta_2=0.999)
# Compile the model
model.compile(optimizer = optimizer , loss = "categorical_crossentropy",
metrics=["accuracy"])
#train the model
model.fit(train_images, train_labels, epochs=10,batch_size=250)
#evaluate accuracy
val_loss, val_acc = model.evaluate(val_images, val_labels)
print('validation accuracy:', val_acc)
print('validation loss:' , val_loss)
Here is the result:
Epoch 1/10
18620/18620 [==============================] - 987s 53ms/step - loss: 2.0487 - acc: 0.39380/18620 [=======>......................] - ETA: 11:57 - loss: 4.0915 - acc: 0.278410500/18620 [===============>..............] - ETA: 7:07 - loss: 2.7013 - acc: 0.325015500/18620 [=======================>......] - ETA: 2:45 - loss: 2.2196 - acc: 0.3754
Epoch 2/10
18620/18620 [==============================] - 985s 53ms/step - loss: 1.1145 - acc: 0.5409TA: 14:05 - loss: 1.1721 - acc: 0.4987 7750/18620 [===========>..................] - ETA: 9:31 - loss: 1.1378 - acc: 0.5288 - ETA: 2:44 - loss: 1.1183 - acc: 0.5392
Epoch 3/10
18620/18620 [==============================] - 978s 53ms/step - loss: 1.0331 - acc: 0.5830TA: 14:17 - loss: 1.0323 - acc: 0.5845
Epoch 4/10
18620/18620 [==============================] - 975s 52ms/step - loss: 1.0032 - acc: 0.5942TA: 9:37 - loss: 1.0127 - acc: 0.5875 9750/18620 [==============>...............] - ETA: 7:41 - loss: 1.0119 - acc: 0.5892 - ETA: 5:19 - loss: 1.0122 - acc: 0.5902
Epoch 5/10
18620/18620 [==============================] - 973s 52ms/step - loss: 0.9680 - acc: 0.6137TA: 11:27 - loss: 0.9670 - acc: 0.6137 7000/18620 [==========>...................] - ETA: 9:58 - loss: 0.9718 - acc: 0.6066 15000/18620 [=======================>......] - ETA: 3:08 - loss: 0.9694 - acc: 0.6115
Epoch 6/10
18620/18620 [==============================] - 979s 53ms/step - loss: 0.9308 - acc: 0.62960/18620 [=============>................] - ETA: 8:36 - loss: 0.9311 - acc: 0.633110500/18620 [===============>..............] - ETA: 7:05 - loss: 0.9310 - acc: 0.6304
Epoch 7/10
18620/18620 [==============================] - 976s 52ms/step - loss: 0.9052 - acc: 0.63860/18620 [==========>...................] - ETA: 10:02 - loss: 0.9112 - acc: 0.6347 - ETA: 9:11 - loss: 0.9055 - acc: 0.6368 - ETA: 5:19 - loss: 0.9105 - acc: 0.6362
Epoch 8/10
18620/18620 [==============================] - 1008s 54ms/step - loss: 0.8755 - acc: 0.6507/18620 [==================>...........] - ETA: 5:52 - loss: 0.8746 - acc: 0.6513
Epoch 9/10
18620/18620 [==============================] - 994s 53ms/step - loss: 0.8479 - acc: 0.66140/18620 [===>..........................] - ETA: 14:12 - loss: 0.8474 - acc: 0.6560 3500/18620 [====>.........................] - ETA: 13:27 - loss: 0.8437 - acc: 0.6566 - ETA: 11:54 - loss: 0.8318 - acc: 0.6672 - ETA: 9:30 - loss: 0.8273 - acc: 0.6681 9500/18620 [==============>...............] - ETA: 8:08 - loss: 0.8390 - acc: 0.6653 - ETA: 6:09 - loss: 0.8399 - acc: 0.6660 - ETA: 1:53 - loss: 0.8473 - acc: 0.6628
Epoch 10/10
18620/18620 [==============================] - 997s 54ms/step - loss: 0.8108 - acc: 0.67490/18620 [=======>......................] - ETA: 11:54 - loss: 0.8146 - acc: 0.6650 - ETA: 10:45 - loss: 0.8196 - acc: 0.6652
4656/4656 [==============================] - 40s 9ms/stepETA: 1s
validation accuracy: 0.6265034364261168
validation loss: 0.964772748373628
Upvotes: 0
Views: 2169
Reputation: 1
You may need to tune the exact values of filters depending on
If your input images are greater than 128×128 you may choose to use a kernel size > 3.
If your images are smaller than 128×128 you may want to consider sticking with strictly 1×1 and 3×3 filters.
Also use Adam optimiser with its original values.
Upvotes: 0
Reputation: 171
At the first you can increase CNN filters (8 or 16 is not enough)and then use BatchNormalization layers after MaxPool layers. If it's not work change the optimizer (like SGD etc.)
Upvotes: 2