title: Keras callback AttributeError: 'ModelCheckpoint' object has no attribute '_implements_train_batch_hooks'
body: <p>I'm using Keras (with TensorFlow back-end) to implement a neural network and want to only save the model that minimises loss on the validation set during training. To do this, I instantiated a ModelCheckpoint and pass it when calling the fit method of the model. However, when I do this I get the following error: "<code>AttributeError: 'ModelCheckpoint' object has no attribute '_implements_train_batch_hooks'</code>". The closest thing I have found online for my problem is <a href="https://stackoverflow.com/questions/57122907/tensorboard-attributeerror-modelcheckpoint-object-has-no-attribute-on-train">this post</a> with a similar error, where the problem came from mixing modules from <code>keras</code> and <code>tf.keras</code>, however this is not my case as all my modules are imported from <code>keras</code>. I've been looking online and through the Keras documentation for a while and can't find anything that could explain this bug. Here are the parts of the code that seem the most relevant to the issue: </p>
  
  <p><strong>Imported modules</strong>: </p>
  
  <pre><code>from keras.models import Sequential
  from keras.layers import Embedding, Conv1D, Dense, Dropout, GlobalMaxPool1D, Concatenate
  from keras.callbacks import ModelCheckpoint
  </code></pre>
  
  <p><strong>ModelCheckpoint instantiation, model compilation and call to fit method:</strong> </p>
  
  <pre><code>checkpoint = ModelCheckpoint('../model_best.h5', monitor='val_loss', verbose=1, save_best_only=True, mode='min')
  
  model.compile(loss='binary_crossentropy',
                optimizer='adam',
                metrics=['accuracy'])
  
  history = model.fit(x_train, y_train, 
                      epochs = 10, batch_size = 64,
                      validation_data = (x_val, y_val),
                      callbacks = [checkpoint])
  </code></pre>
  
  <p>...and here is the full Traceback: </p>
  
  <pre><code>Traceback (most recent call last):
  
    File "/Users/thisuser/thisrepo/classifier.py", line 39, in &lt;module&gt;
      callbacks = [checkpoint])
  
    File "/Users/thisuser/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 66, in _method_wrapper
      return method(self, *args, **kwargs)
  
    File "/Users/thisuser/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 826, in fit
      steps=data_handler.inferred_steps)
  
    File "/Users/thisuser/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py", line 231, in __init__
      cb._implements_train_batch_hooks() for cb in self.callbacks)
  
    File "/Users/thisuser/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py", line 231, in &lt;genexpr&gt;
      cb._implements_train_batch_hooks() for cb in self.callbacks)
  
  AttributeError: 'ModelCheckpoint' object has no attribute '_implements_train_batch_hooks'
  </code></pre>
  
  <p>The versions I'm using are: </p>
  
  <ul>
  <li>Python: 3.7.7</li>
  <li>Keras: 2.3.0-tf</li>
  </ul>
  
  <p>Does anyone know what might be causing the issue? If needed I can modify my code slightly to give it all here, so that it is reproducible. Thanks in advance for your help!</p>