title: How to increase the accuracy of the keras model and prevent overfitting
body: <p>I am trying to train</p>
  
  <pre><code>model.add(Conv2D(32, (3, 3), kernel_initializer='random_uniform', activation='relu', input_shape=(x1, x2, depth)))
  model.add(MaxPool2D(pool_size=(2, 2)))
  model.add(Dropout(0.5))
  
  model.add(BatchNormalization())
  model.add(Conv2D(64, (3, 3), activation='relu'))
  model.add(MaxPool2D(pool_size=(2, 2)))
  model.add(Dropout(0.4))
  
  model.add(Conv2D(64, 3, 3))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  model.add(BatchNormalization())
  model.add(Dropout(0.2))
  
  model.add(Flatten())
  
  model.add(Dense(128, activation='relu'))
  model.add(Dropout(0.3))
  
  model.add(Dense(3, activation='softmax'))
  </code></pre>
  
  <p>Here's how I'm compiling it:</p>
  
  <pre><code>sgd = optimizers.SGD(lr=0.1, decay=0.0, momentum=0.05, nesterov=True)
  model.compile(loss='categorical_crossentropy',
            optimizer=sgd,
            metrics=['accuracy'])
  </code></pre>
  
  <p>I've tried various learning rates and different optimizers. But the accuracy doesn't seem to go beyond 50% as shown below:
  <a href="https://i.stack.imgur.com/bGjXX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bGjXX.png" alt="enter image description here"></a></p>
  
  <p>My images are properly normalized around 0 with STD as 1. </p>
  
  <p>Is there something I am missing? How can I improve the accuracy of the model?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Hey, when I use the following data generator:</p>
  
  <pre><code>train_datagen = ImageDataGenerator(
      featurewise_center=True,
      featurewise_std_normalization=True,
      rotation_range=20,
      width_shift_range=0.2,
      height_shift_range=0.2,
      horizontal_flip=True)
  test_datagen = ImageDataGenerator(featurewise_center=True,
      featurewise_std_normalization=True)
  
  
  
  train_generator = train_datagen.flow(np.array(X_train), batch_size=batchsize)
  valid_generator = test_datagen.flow(np.array(X_test), batch_size = batchsize)
  
  history = model.fit_generator(train_datagen.flow(np.array(X_train), y_train_cat, batch_size=batchsize),
                      steps_per_epoch=len(X_train) // batchsize, epochs=epochs, 
                      validation_data= valid_generator, 
                      validation_steps=len(X_test) // batchsize)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>TypeError: '>' not supported between instances of 'int' and 'str'</p>
  </blockquote>
  
  <p>I used to solve this by either updating <code>numpy</code> or uninstalling it and installing it again, but this time, it's not working with either. Can you help me with it?</p>