当我尝试使用Tesorboard监控培训时,我正在运行一个简单的神经网络与Keras,后端Tensorflow。
我的模型如下:
import keras
from keras.layers.core import Dense, Activation, Dropout
from keras.models import Sequential
model = Sequential()
model.add(Dense(32, input_dim=500))
model.add(Activation('relu'))
model.add(Dropout(0.2))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
我尝试使用以下配置运行它:
tensorboard = keras.callbacks.TensorBoard(log_dir="../TFlogs",
histogram_freq=2, batch_size=300,
write_grads=True, write_images=True)
one_hot_labels = keras.utils.to_categorical(y_train, num_classes=2)
history = model.fit(X_train, one_hot_labels, epochs=10,
validation_split=0.1, batch_size=300, callbacks=[tensorboard])
但由于某种原因,我收到以下错误:
File "C:/Users/user/PycharmProjects/SpamFilter/Filter/NeuralModel.py", line 108, in fit
history = model.fit(X_train, one_hot_labels, epochs=10, validation_split=0.1, batch_size=300, callbacks=[tensorboard])
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\keras\models.py", line 1002, in fit
validation_steps=validation_steps)
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\keras\engine\training.py", line 1705, in fit
validation_steps=validation_steps)
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\keras\engine\training.py", line 1256, in _fit_loop
callbacks.on_epoch_end(epoch, epoch_logs)
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\keras\callbacks.py", line 77, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\keras\callbacks.py", line 855, in on_epoch_end
result = self.sess.run([self.merged], feed_dict=feed_dict)
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\tensorflow\python\client\session.py", line 905, in run
run_metadata_ptr)
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\tensorflow\python\client\session.py", line 1109, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
File "C:\Users\user\PycharmProjects\SpamFilter\venvKeras\lib\site-packages\numpy\core\numeric.py", line 492, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.
当我设置TensorBoard
选项histogram_freq=0
我没有得到错误,但我想得到直方图信息有人可以帮我找到原因吗?
在创建模型之前尝试运行K.clear_session()
。
请参阅此GitHub thread以获取此错误的参考。