title: CNN Model With Low Accuracy
body: <p>I'm currently working on a CNN model that classifies food images. So far, I have managed to build a functioning CNN but I would like to improve the accurracy. For the dataset, I have used some images from Kaggle and few from my own collection. </p>
  
  <p>Here is some information about the dataset:</p>
  
  <ol>
  <li>There are 91 classes of food images.</li>
  <li>Each class has around 500 to 650 images.</li>
  <li>The dataset has been manually cleaned and checked for unrelated or bad quality images (<em>the photos are of different sizes</em>).</li>
  </ol>
  
  <p>Here is my CNN model:</p>
  
  <pre><code>classifier = Sequential()
  
  def cnn_layer_creation(classifier):
  
  classifier.add(InputLayer(input_shape=[224,224,3]))
  
  classifier.add(Conv2D(filters=32,kernel_size=5,strides=1,padding='same',activation='relu',data_format='channels_first'))
  classifier.add(MaxPooling2D(pool_size=5,padding='same'))
  
  classifier.add(Conv2D(filters=50,kernel_size=5,strides=1,padding='same',activation='relu'))
  classifier.add(MaxPooling2D(pool_size=5,padding='same'))
  
  classifier.add(Conv2D(filters=80,kernel_size=5,strides=1,padding='same',activation='relu',data_format='channels_last'))
  classifier.add(MaxPooling2D(pool_size=5,padding='same'))
  
  classifier.add(Dropout(0.25))
  classifier.add(Flatten())
  classifier.add(Dense(64,activation='relu'))
  classifier.add(Dropout(rate=0.5))
  classifier.add(Dense(91,activation='softmax'))
  
  # Compiling the CNN
  classifier.compile(optimizer="RMSprop", loss = 'categorical_crossentropy', metrics = ['accuracy'])
  data_initialization(classifier)
  
  def data_initialization(classifier):
  
  # Part 2 - Fitting the CNN to the images
  
  from keras.preprocessing.image import ImageDataGenerator
  
  train_datagen = ImageDataGenerator(rescale = 1./255,
                                     shear_range = 0.2,
                                     zoom_range = 0.2,
                                     horizontal_flip = True)
  
  test_datagen = ImageDataGenerator(rescale = 1./255,
                                    shear_range = 0.2,
                                    zoom_range = 0.2,
                                    horizontal_flip = True)
  
  training_set = train_datagen.flow_from_directory('food_image/train',
                                                   target_size = (224, 224),
                                                   batch_size = 100,
                                                   class_mode = 'categorical')
  
  test_set = test_datagen.flow_from_directory('food_image/test',
                                              target_size = (224, 224),
                                              batch_size = 100,
                                              class_mode = 'categorical')
  
  classifier.fit_generator(training_set,
                           steps_per_epoch = 100,
                           epochs = 100,
                           validation_data = test_set,
                           validation_steps = 100)
  
  classifier.save("brynModelGPULite.h5")
  classifier.summary()
  
  def main():
  
  cnn_layer_creation(classifier)
  </code></pre>
  
  <p><em>Training is done on GPU (nVidia 980M)</em></p>
  
  <p>Unfortunately, the accuracy has not exceeded 10%. Things I've tried are:</p>
  
  <ol>
  <li><p>Increase the number of epochs.</p></li>
  <li><p>Change the optimizer (ADAM, RMSPROP).</p></li>
  <li><p>Change the activation function.</p></li>
  <li><p>Reduce the image input size.</p></li>
  <li><p>Increase the batch size.</p></li>
  <li><p>Change the filter size to 32, 64, 128.</p></li>
  </ol>
  
  <p>None of these have improved the accuracy.</p>
  
  <p>Could anyone shine some light on how I might improve my model accuracy?</p>