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

AttributeError: 'TensorBoardColabCallback' object has no attribute 'on_train_batch_begin' #11

Open
francisco-fernandes opened this issue May 1, 2019 · 4 comments

Comments

@francisco-fernandes
Copy link

Hello!
It seems that the latest 1.x version of Keras+Tensorflow requires an on_train_batch_begin function definition that is missing...

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-f2f738e2066b> in <module>()
      2 with session.as_default(), graph.as_default() :
      3   model.set_weights(weights)
----> 4   result = model.fit(X_train, y_train, batch_size=32, epochs=100, verbose=0, shuffle=False, validation_data=(X_test, y_test), callbacks=[PrintDots(),TensorBoardColabCallback(tbc)])
      5 end_time = time.perf_counter()
      6 print( "time = " + str(end_time - start_time) + "s" )

2 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/callbacks.py in _call_batch_hook(self, mode, hook, batch, logs)
    194     t_before_callbacks = time.time()
    195     for callback in self.callbacks:
--> 196       batch_hook = getattr(callback, hook_name)
    197       batch_hook(batch, logs)
    198     self._delta_ts[hook_name].append(time.time() - t_before_callbacks)

AttributeError: 'TensorBoardColabCallback' object has no attribute 'on_train_batch_begin'

These are the versions of Tensorflow, Keras and tensorboardcolab that I'm using, respectively, which already come pre-installed in Google Colab:

1.13.1
2.2.4-tf
Requirement already up-to-date: tensorboardcolab in /usr/local/lib/python3.6/dist-packages (0.0.22)

Any workaround for this issue?
Thanks!

@smatterchoo
Copy link

same issue here while running the mnist keras tutorial

@r-or
Copy link

r-or commented May 8, 2019

If you can switch to tensorflow 2.0, there's now an official implementation: click

It works well, especially if you want to embed tensorboard into colab directly. Although I have to say it is a bit bothersome, I like the possibility of using a separate tab.

If not, maybe you can try to create a wrapper object of the likes:

tbc = ...
class custom_callback(TensorBoardColabCallback):
  def __init__(self, *args, **kwargs):
    super().__init__(self, *args, **kwargs)

  def on_train_batch_begin(self, *args, **kwargs):
    pass

...
model.fit(..., callbacks=[custom_callback(tbc)])

@ptrk8
Copy link

ptrk8 commented Jul 20, 2019

@r-or This request comes from my lack of Python object oriented knowledge but would you be able to explain what should be going into the ellipsis for tbc? Alternatively, I more complete example would be appreciated :)

@AndreaRigoni
Copy link

This fixed the issue for me:

class PlotLossesCallback(livelossplot.keras.PlotLossesCallback):
    def on_train_batch_begin(self, a, b): pass
    def on_train_batch_end(self, a, b): pass

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

5 participants