I'm getting an error while creating a log file using TensorBoard with Keras.
The code
import pandas as pd
from keras.callbacks import TensorBoard
from keras.models import Sequential
from keras.layers import *
training_data_df = pd.read_csv("sales_data_training_scaled.csv")
X = training_data_df.drop('total_earnings', axis=1).values
Y = training_data_df[['total_earnings']].values
# Define the model
model = Sequential()
model.add(Dense(50, input_dim=9, activation='relu', name='layer_1'))
model.add(Dense(100, activation='relu', name='layer_2'))
model.add(Dense(50, activation='relu', name='layer_3'))
model.add(Dense(1, activation='linear', name='output_layer'))
model.compile(loss='mean_squared_error', optimizer='adam')
# Create a TensorBoard logger
logger = TensorBoard(
log_dir='logs',
histogram_freq=5,
write_graph=True
)
# Train the model
model.fit(
X,
Y,
epochs=50,
shuffle=True,
verbose=2,
callbacks=[logger]
)
# Load the separate test data set
test_data_df = pd.read_csv("sales_data_test_scaled.csv")
X_test = test_data_df.drop('total_earnings', axis=1).values
Y_test = test_data_df[['total_earnings']].values
test_error_rate = model.evaluate(X_test, Y_test, verbose=0)
print(test_error_rate)
Then I got this error:
Traceback (most recent call last):
File "E:/Building.Deep.Learning.Applications.with.Keras.2.0/Exercise Files/06/model_logging final.py", line 34, in callbacks=[logger]
File "C:\Python3.6.4\lib\site-packages\keras\engine\training.py", line 1041, in fit steps_per_epoch=steps_per_epoch)
File "C:\Python3.6.4\lib\site-packages\keras\engine\training_arrays.py", line 219, in fit_loop callbacks.on_epoch_end(epoch, epoch_logs)
File "C:\Python3.6.4\lib\site-packages\keras\callbacks.py", line 77, in on_epoch_end callback.on_epoch_end(epoch, logs)
File "C:\Python3.6.4\lib\site-packages\keras\callbacks.py", line 865, in on_epoch_end
raise ValueError("If printing histograms, validation_data must be " ValueError: If printing histograms, validation_data must be provided, and cannot be a generator.