title: Keras using too much memory
body: <p>I have a keras (with tensorflow backend) model which is defined like so:</p>
  
  <pre><code>INPUT_SHAPE = [4740, 3540, 1]
  
  model = Sequential()
  model.add(Conv2D(32, kernel_size=(3, 3),
                   activation='relu',
                   input_shape=INPUT_SHAPE))
  model.add(Conv2D(2, (4, 4), strides=(1, 1), activation='relu'))
  model.add(MaxPooling2D(pool_size=(4, 4)))
  model.add(Conv2D(4, (4, 4), strides=(1, 1), activation='relu'))
  model.add(MaxPooling2D(pool_size=(4, 4)))
  model.add(Conv2D(8, (4, 4), strides=(1, 1), activation='relu'))
  model.add(MaxPooling2D(pool_size=(4, 4)))
  model.add(Conv2D(16, (4, 4), strides=(1, 1), activation='relu'))
  model.add(MaxPooling2D(pool_size=(4, 4)))
  model.add(Conv2D(32, (4, 4), strides=(1, 1), activation='relu'))
  model.add(MaxPooling2D(pool_size=(4, 4)))
  model.add(Dropout(0.25))
  model.add(Flatten())
  model.add(Dense(128, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(num_classes, activation='softmax'))
  
  model.compile(loss=keras.losses.categorical_crossentropy,
                optimizer=keras.optimizers.Adadelta(),
                metrics=['accuracy'])
  </code></pre>
  
  <p>This model has only 37,506 trainable params. Yet somehow it is able to deplete K80's 12GB vram resource on model.fit() if a batch size is more then 1.
  Why does this model need so much memory?
  And how do I calculate memory requirements properly?
  The function from <a href="https://stackoverflow.com/questions/43137288/how-to-determine-needed-memory-of-keras-model">How to determine needed memory of Keras model?</a> gives me 2.15 GB per 1 element in a batch. So at least I should be able to make a batch of 5.</p>
  
  <p>EDIT: model.summary()</p>
  
  <pre><code>Layer (type)                 Output Shape              Param #   
  =================================================================
  conv2d_1 (Conv2D)            (None, 4738, 3538, 32)    320       
  _________________________________________________________________
  conv2d_2 (Conv2D)            (None, 4735, 3535, 2)     1026      
  _________________________________________________________________
  max_pooling2d_1 (MaxPooling2 (None, 1183, 883, 2)      0         
  _________________________________________________________________
  conv2d_3 (Conv2D)            (None, 1180, 880, 4)      132       
  _________________________________________________________________
  max_pooling2d_2 (MaxPooling2 (None, 295, 220, 4)       0         
  _________________________________________________________________
  conv2d_4 (Conv2D)            (None, 292, 217, 8)       520       
  _________________________________________________________________
  max_pooling2d_3 (MaxPooling2 (None, 73, 54, 8)         0         
  _________________________________________________________________
  conv2d_5 (Conv2D)            (None, 70, 51, 16)        2064      
  _________________________________________________________________
  max_pooling2d_4 (MaxPooling2 (None, 17, 12, 16)        0         
  _________________________________________________________________
  conv2d_6 (Conv2D)            (None, 14, 9, 32)         8224      
  _________________________________________________________________
  max_pooling2d_5 (MaxPooling2 (None, 3, 2, 32)          0         
  _________________________________________________________________
  dropout_1 (Dropout)          (None, 3, 2, 32)          0         
  _________________________________________________________________
  flatten_1 (Flatten)          (None, 192)               0         
  _________________________________________________________________
  dense_1 (Dense)              (None, 128)               24704     
  _________________________________________________________________
  dropout_2 (Dropout)          (None, 128)               0         
  _________________________________________________________________
  dense_2 (Dense)              (None, 4)                 516       
  =================================================================
  Total params: 37,506
  Trainable params: 37,506
  Non-trainable params: 0
  _________________________________________________________________
  </code></pre>