juglab/n2v

'ReduceLROnPlateau' object has no attribute '_implements_predict_batch_hooks'

joaomamede opened this issue · 2 comments

N2v 0.3.0
tensorflow '2.2.0'
python 3.7.10

When I use the code that used to work with n2v in Tf 1.x I have the following error:
(I tried adding from tensorflow.keras.callbacks import ReduceLROnPlateau in n2v_standard)

history = model.train(X, X_val)

Using TensorFlow backend.
8 blind-spots will be generated per training patch of size (64, 64).
Preparing validation data: 100%|██████████| 62/62 [00:00<00:00, 2474.73it/s]

AttributeError Traceback (most recent call last)
in
----> 1 history = model.train(X, X_val)

~/anaconda3/lib/python3.7/site-packages/n2v/models/n2v_standard.py in train(self, X, validation_X, epochs, steps_per_epoch)
251 history = self.keras_model.fit(iter(training_data), validation_data=(validation_X, validation_Y),
252 epochs=epochs, steps_per_epoch=steps_per_epoch,
--> 253 callbacks=self.callbacks, verbose=1)
254
255 if self.basedir is not None:

~/anaconda3/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.

~/anaconda3/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

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in init(self, callbacks, add_history, add_progbar, model, **params)
233 cb._implements_test_batch_hooks() for cb in self.callbacks)
234 self._should_call_predict_batch_hooks = any(
--> 235 cb._implements_predict_batch_hooks() for cb in self.callbacks)
236 # pylint: enable=protected-access
237

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in (.0)
233 cb._implements_test_batch_hooks() for cb in self.callbacks)
234 self._should_call_predict_batch_hooks = any(
--> 235 cb._implements_predict_batch_hooks() for cb in self.callbacks)
236 # pylint: enable=protected-access
237

AttributeError: 'ReduceLROnPlateau' object has no attribute '_implements_predict_batch_hooks'

Fixed by changing
n2v/models/n2v_standard.py
Line 307
from keras.callbacks import ReduceLROnPlateau

to

from tensorflow.keras.callbacks import ReduceLROnPlateau

Thank you for reporting. This should be fixed now on master. I will release n2v v0.3.1 right away.