Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute error occur in Lamdacallback #31

Open
prateekvyas1996 opened this issue Aug 19, 2020 · 3 comments
Open

Attribute error occur in Lamdacallback #31

prateekvyas1996 opened this issue Aug 19, 2020 · 3 comments

Comments

@prateekvyas1996
Copy link

I am using the latest version of tensorflow and keras and while running LRfinder class i got an error as shown below


AttributeError Traceback (most recent call last)
in
1 from keras_lr_finder.lr_finder import*
2 lr_finder = lf.LRFinder(model_seq)
----> 3 lr_finder.find(input_data, labels, start_lr=0.0001, end_lr=1, epochs=5)

D:\Deep_learning_projects\aryan\keras_lr_finder\lr_finder.py in find(self, x_train, y_train, start_lr, end_lr, batch_size, epochs, **kw_fit)
62 batch_size=batch_size, epochs=epochs,
63 callbacks=[callback],
---> 64 **kw_fit)
65
66 # Restore the weights to the state before model fitting

c:\programdata\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\keras\engine\training.py in _method_wrapper(self, *args, **kwargs)
106 def _method_wrapper(self, *args, **kwargs):
107 if not self._in_multi_worker_mode(): # pylint: disable=protected-access
--> 108 return method(self, *args, **kwargs)
109
110 # Running inside run_distribute_coordinator already.

c:\programdata\anaconda3\envs\deeplearning\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)
1072 verbose=verbose,
1073 epochs=epochs,
-> 1074 steps=data_handler.inferred_steps)
1075
1076 self.stop_training = False

c:\programdata\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\keras\callbacks.py in init(self, callbacks, add_history, add_progbar, model, **params)
233 # pylint: disable=protected-access
234 self._should_call_train_batch_hooks = any(
--> 235 cb._implements_train_batch_hooks() for cb in self.callbacks)
236 self._should_call_test_batch_hooks = any(
237 cb._implements_test_batch_hooks() for cb in self.callbacks)

c:\programdata\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\keras\callbacks.py in (.0)
233 # pylint: disable=protected-access
234 self._should_call_train_batch_hooks = any(
--> 235 cb._implements_train_batch_hooks() for cb in self.callbacks)
236 self._should_call_test_batch_hooks = any(
237 cb._implements_test_batch_hooks() for cb in self.callbacks)

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

@arthur-ver
Copy link

arthur-ver commented Aug 20, 2020

Try installing keras-lr-finder from git using pip install git+https://github.com/surmenok/keras_lr_finder, instead of pip install keras-lr-finder

I've had a similar error and it worked for me. Hope this helps you too!

@prateekvyas1996
Copy link
Author

prateekvyas1996 commented Aug 20, 2020 via email

@lydiazajiczek
Copy link

lydiazajiczek commented Mar 31, 2022

(This is for Keras/TensorFlow version 2.3.0)

If you are limited to what tensorflow/keras version you can install (because of the CUDA version you have installed, for example) I found that editing the import statements let me run this. Specifically:
import keras.backend as K --> replace all instances of K with tf.compat.v1.keras.backend
e.g. on line 24 of lr_finder.py:
lr = K.get_value(self.model.optimizer.lr) --> lr = tf.compat.v1.keras.backend.get_value(self.model.optimizer.lr)

I also had to change from keras.callbacks import LambdaCallback to from tensorflow.keras.callbacks import LambdaCallback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants