title: How to accumulate gradients for large batch sizes in Keras
body: <p>I am working with a very memory demanding CNN model for a task of classification.
  This poses a big limit on the batch size that I can use during training.</p>
  
  <p>One solution is to accumulate the gradients during training, meaning that the weights of the model are not updated after every single batch. Instead the same weights are used for several batches, while the gradients from each batch are accumulated and than averaged for a single weight-update action.</p>
  
  <p>I'm using a Tensorflow backend Keras and I'm pretty sure that Keras has no off-the-shelf function/method to achieve this.</p>
  
  <p>How can it be done for a Keras/tensorflow model?</p>