System information
You can collect some of this information using our environment capture script
You can also obtain the TensorFlow version with
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
v1.12.0-rc2-3-ga6d8ffae09 1.12.0
Describe the current behavior
I want to use the tensorboard callback in keras to show the embeddings in the projector view
Describe the expected behavior
I'm getting an error while training.
Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.
tensorboard = keras.callbacks.TensorBoard(
log_dir='./logs',
batch_size=128,
histogram_freq=1,
embeddings_freq=1,
embeddings_metadata='./metadata.tsv',
embeddings_data=X_Test
)
history = model.fit(ready_data, ready_labels, batch_size=128, epochs=20,validation_data=(X_Test,Y_test),callbacks=[tensorboard])
Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.
Traceback (most recent call last):
File "/Users/alcaljos/Projects/issue-classifer-ml/src/main.py", line 193, in <module>
history = model.fit(ready_data, ready_labels, batch_size=128, epochs=20,validation_data=(X_Test,Y_test),callbacks=[tensorboard,checkpointer])
File "/Users/alcaljos/anaconda/envs/issue-classifier/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1639, in fit
validation_steps=validation_steps)
File "/Users/alcaljos/anaconda/envs/issue-classifier/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_arrays.py", line 239, in fit_loop
callbacks.on_epoch_end(epoch, epoch_logs)
File "/Users/alcaljos/anaconda/envs/issue-classifier/lib/python3.6/site-packages/tensorflow/python/keras/callbacks.py", line 214, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "/Users/alcaljos/anaconda/envs/issue-classifier/lib/python3.6/site-packages/tensorflow/python/keras/callbacks.py", line 1144, in on_epoch_end
self.sess.run(self.assign_embeddings, feed_dict=feed_dict)
AttributeError: 'TensorBoard' object has no attribute 'sess'
Encountered same problem when using Tensorboard as Keras callback on Colab with Python3 environment:
from tensorflow.python.keras.callbacks import TensorBoard
callbacks = [
TensorBoard(
'./logs',
write_graph=True,
embeddings_freq=1,
embeddings_data=x
)
]
model.fit(x, y, callbacks=callbacks)
Error message:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/callbacks.py in on_epoch_end(self, epoch, logs)
1142 feed_dict[K.learning_phase()] = False
1143
-> 1144 self.sess.run(self.assign_embeddings, feed_dict=feed_dict)
1145 self.saver.save(self.sess,
1146 os.path.join(self.log_dir, 'keras_embedding.ckpt'),
AttributeError: 'TensorBoard' object has no attribute 'sess'
I faced the same problem. Then inside __init__ method of callbacks.TensorBoard class, I did this:
self.sess = K.get_session()
And it worked.
So, I think, this may be bug. Not sure, if this is worth PR.
I get the same error when using tensorflow.python.keras.callbacks.TensorBoard from Tensorflow 1.12.0 and TensorBoard 1.12.2
As a temporary workaround, just overwrite the existing TensorBoard with a new one, that has a session:
class TensorBoardWithSession(tf.keras.callbacks.TensorBoard):
def __init__(self, **kwargs):
from tensorflow.python.keras import backend as K
self.sess = K.get_session()
super().__init__(**kwargs)
tf.keras.callbacks.TensorBoard = TensorBoardWithSession
Then, just continue using TensorBoard normally.
Does this problem exist with the latest Tensorboard version (1.13) ?
@omalleyt12 It looks like the self.sess attribute on the V1 TensorBoard keras callback is no longer set as of your change in https://github.com/tensorflow/tensorflow/commit/d4cb01f242dc3ff0f7b0aae7284def46281755f2
Could you take a look at how we should update the remaining reference? I think it's only used for logging embeddings which is probably why more people haven't hit this error: https://github.com/tensorflow/tensorflow/blob/3c3bf0873de4ef3f5c71b624a62319aa114133a7/tensorflow/python/keras/callbacks_v1.py#L441-L444
This should be fixed now
Fixed by https://github.com/tensorflow/tensorflow/commit/d994300bde00c7dee8bacccdbc5d67c3f3f2b322
This fix should be available in the upcoming 1.14 release of TensorFlow, or you can check out the nightly release tf-nightly, which should already have it.
Most helpful comment
Fixed by https://github.com/tensorflow/tensorflow/commit/d994300bde00c7dee8bacccdbc5d67c3f3f2b322
This fix should be available in the upcoming 1.14 release of TensorFlow, or you can check out the nightly release
tf-nightly, which should already have it.