keras-one-cycle icon indicating copy to clipboard operation
keras-one-cycle copied to clipboard

AttributeError: 'LRFinder' object has no attribute '_implements_train_batch_hooks'

Open jinusean opened this issue 4 years ago • 2 comments

I received this output when using data generators:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-1aa4d91b8f8d> in <module>
      1 model.compile(optimizer='adam', loss=losses.CategoricalCrossentropy(),metrics=['accuracy'])
      2 lr_callback = LRFinder(train_generator.n, train_generator.batch_size)
----> 3 history = model.fit_generator(train_generator, validation_data=val_generator, epochs=10, callbacks = [lr_callback])

/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
    322               'in a future version' if date is None else ('after %s' % date),
    323               instructions)
--> 324       return func(*args, **kwargs)
    325     return tf_decorator.make_decorator(
    326         func, new_func, 'deprecated',

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   1477         use_multiprocessing=use_multiprocessing,
   1478         shuffle=shuffle,
-> 1479         initial_epoch=initial_epoch)
   1480 
   1481   @deprecation.deprecated(

/opt/conda/lib/python3.7/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.

/opt/conda/lib/python3.7/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

/opt/conda/lib/python3.7/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)

/opt/conda/lib/python3.7/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: 'LRFinder' object has no attribute '_implements_train_batch_hooks'

jinusean avatar Jun 22 '20 10:06 jinusean

I also got the same error when trying to run this code

jagar2 avatar Jul 08 '20 16:07 jagar2

Had the same error when switching over to TF2, Assuming you are also running TF2 the two keras imports in clr.py can be switched to

from tensorflow.keras.callbacks import Callback
from tensorflow.keras import backend as K

ecatkins avatar Sep 14 '20 13:09 ecatkins