AttributeError: 'ModelCheckpoint' object has no attribute '_implements_train_batch_hooks'
See original GitHub issueI was using ModelCheckpoint from keras for model traing.Here is the code:
model1.compile(loss={'ctc': lambda y_true, y_pred: y_pred}, optimizer = 'adam')
filepath="model.hdf5"
checkpoint = ModelCheckpoint(filepath=filepath, monitor='val_loss', verbose=1, save_best_only=True, mode='auto')
# fitting model
model1.fit(x = [ IMAGES , LABELS_PADDED , IMAGES_LENGTH , LABELS_LENGTH ], y=np.zeros(len(IMAGES)) , batch_size = 256 , epochs = 1000 , validation_split = 0.33 , verbose = 1, callbacks = [ checkpoint ] )
And I encountered this error:
AttributeError Traceback (most recent call last)
<ipython-input-84-de48273d352a> in <module>
1 # fitting model
2
----> 3 model1.fit(x = [ IMAGES , LABELS_PADDED , IMAGES_LENGTH , LABELS_LENGTH ], y=np.zeros(len(IMAGES)) , batch_size = 256 , epochs = 1000 , validation_split = 0.33 , verbose = 1, callbacks = [ checkpoint ] )
~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in _method_wrapper(self, *args, **kwargs)
64 def _method_wrapper(self, *args, **kwargs):
65 if not self._in_multi_worker_mode(): # pylint: disable=protected-access
---> 66 return method(self, *args, **kwargs)
67
68 # Running inside `run_distribute_coordinator` already.
~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
824 verbose=verbose,
825 epochs=epochs,
--> 826 steps=data_handler.inferred_steps)
827
828 self.stop_training = False
~\anaconda3\lib\site-packages\tensorflow\python\keras\callbacks.py in __init__(self, callbacks, add_history, add_progbar, model, **params)
229 # pylint: disable=protected-access
230 self._should_call_train_batch_hooks = any(
--> 231 cb._implements_train_batch_hooks() for cb in self.callbacks)
232 self._should_call_test_batch_hooks = any(
233 cb._implements_test_batch_hooks() for cb in self.callbacks)
~\anaconda3\lib\site-packages\tensorflow\python\keras\callbacks.py in <genexpr>(.0)
229 # pylint: disable=protected-access
230 self._should_call_train_batch_hooks = any(
--> 231 cb._implements_train_batch_hooks() for cb in self.callbacks)
232 self._should_call_test_batch_hooks = any(
233 cb._implements_test_batch_hooks() for cb in self.callbacks)
AttributeError: 'ModelCheckpoint' object has no attribute '_implements_train_batch_hooks'
How to resolve this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Keras callback AttributeError: 'ModelCheckpoint' object has no ...
Solution: since the developers of keras require everyone to switch to the version tf.keras, you need to replace of your code import section....
Read more >Tensorboard AttributeError: 'ModelCheckpoint' object has no ...
I'm currently using Tensorboard using the below callback as outlined by this SO post as shown below. from keras.callbacks import ModelCheckpoint.
Read more >AttributeError: 'ModelCheckpoint' object has no attribute ...
在运行的时候报错:AttributeError: 'ModelCheckpoint' object has no attribute 'on_train_batch_begin' 应该将from keras.callbacks import ...
Read more >tf.keras.callbacks.ModelCheckpoint | TensorFlow v2.11.0
ModelCheckpoint callback is used in conjunction with training using model.fit() to save a model or weights (in a checkpoint file) at some ...
Read more >how to load weights (saved using callbacks) in R
I could save weights in each epoch during training using keras R. I have ... dots$keywords) : AttributeError: 'str' object has no attribute...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, works for me. Thanks. What I do: replace:
from keras.callbacks import ModelCheckpointby:from tensorflow.keras.callbacks import ModelCheckpointWorked for me as well. I reinstalled tensorflow and keras of lower versions. Then I used this method and it worked for me.