I'm reading the book Deep Learning with Python which uses Keras. In chapter 7, it shows how to use TensorBoard to monitor the training phase progress with an example:
import keras
from keras import layers
from keras.datasets import imdb
from keras.preprocessing import sequence
max_features = 2000
max_len = 500
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
x_train = sequence.pad_sequences(x_train, maxlen=max_len)
x_test = sequence.pad_sequences(x_test, maxlen=max_len)
model = keras.models.Sequential()
model.add(layers.Embedding(max_features, 128, input_length=max_len, name='embed'))
model.add(layers.Conv1D(32, 7, activation='relu'))
model.add(layers.MaxPooling1D(5))
model.add(layers.Conv1D(32, 7, activation='relu'))
model.add(layers.GlobalMaxPooling1D())
model.add(layers.Dense(1))
model.summary()
model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['acc'])
callbacks = [
keras.callbacks.TensorBoard(
log_dir='my_log_dir',
histogram_freq=1,
embeddings_freq=1,
)
]
history = model.fit(x_train, y_train, epochs=20, batch_size=128, validation_split=0.2, callbacks=callbacks)
Apparently, the Keras library has gone through some changes since this code raises some exception:
ValueError: To visualize embeddings, embeddings_data must be provided.
This is after the first epoch is done and the first time the callbacks are run (the first time TensorBoard is run). I know that what is missing is the TensorBoard's parameter embeddings_data. But I don't know what should I assign to it.
Does anyone have a working example for this?
Here are the versions I'm using:
Python: 3.6.5
Keras: 2.2.0
Tensorflow: 1.9.0
[UPDATE]
In order to test any possible solution, I tested this:
import numpy as np
callbacks = [
keras.callbacks.TensorBoard(
log_dir='my_log_dir',
histogram_freq = 1,
embeddings_freq = 1,
embeddings_data = np.arange(0, max_len).reshape((1, max_len)),
)
]
history = model.fit(x_train, y_train, epochs=20, batch_size=128, validation_split=0.2, callbacks=callbacks)
This is the only way I could populate embeddings_data which won't lead to an error. But even though, this does not help either. Still the PROJECTOR tab of the TensorBoard is empty:
Any help is appreciated.
