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

Issue when using Keras callback with tf.keras #12

Open
fmannhardt opened this issue Aug 13, 2019 · 1 comment
Open

Issue when using Keras callback with tf.keras #12

fmannhardt opened this issue Aug 13, 2019 · 1 comment

Comments

@fmannhardt
Copy link

I get the following error when using the Keras callback with tf.keras:

algo-1-bvae4_1 | Traceback (most recent call last):
algo-1-bvae4_1 | File "model.py", line 211, in
algo-1-bvae4_1 | verbose = 2)
algo-1-bvae4_1 | File "/usr/local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 780, in fit
algo-1-bvae4_1 | steps_name='steps_per_epoch')
algo-1-bvae4_1 | File "/usr/local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_arrays.py", line 267, in model_iteration
algo-1-bvae4_1 | callbacks._call_batch_hook(mode, 'begin', step, batch_logs)
algo-1-bvae4_1 | File "/usr/local/lib/python3.6/site-packages/tensorflow/python/keras/callbacks.py", line 247, in _call_batch_hook
algo-1-bvae4_1 | batch_hook = getattr(callback, hook_name)
algo-1-bvae4_1 | AttributeError: 'LosswiseKerasCallback' object has no attribute 'on_train_batch_begin'

I assume those are not compatible? Or does one simply need to add the on_train_batch_begin method?

@fmannhardt
Copy link
Author

It seems that extending it trivially like this solves the issue:

class LosswiseKerasTFCallback(LosswiseKerasCallback):
    
    def __init__(self, tag=None, params={}, track_git=False, display_interval=None, max_iter=None):
        super(LosswiseKerasTFCallback, self).__init__(tag, params, track_git, display_interval, max_iter)
    
    def on_train_batch_begin(self, batch, logs={}):
        return()
    
    def on_train_batch_end(self, batch, logs={}):
        self.on_batch_end(batch, logs)

Maybe this helps someone else tripping over this issue.

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

1 participant