直方图频率激活时Keras Tensorboard错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了直方图频率激活时Keras Tensorboard错误相关的知识,希望对你有一定的参考价值。
当我尝试使用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:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packageskerasmodels.py", line 1002, in fit
validation_steps=validation_steps)
File "C:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packageskerasengine raining.py", line 1705, in fit
validation_steps=validation_steps)
File "C:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packageskerasengine raining.py", line 1256, in _fit_loop
callbacks.on_epoch_end(epoch, epoch_logs)
File "C:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packageskerascallbacks.py", line 77, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "C:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packageskerascallbacks.py", line 855, in on_epoch_end
result = self.sess.run([self.merged], feed_dict=feed_dict)
File "C:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packages ensorflowpythonclientsession.py", line 905, in run
run_metadata_ptr)
File "C:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packages ensorflowpythonclientsession.py", line 1109, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
File "C:UsersuserPycharmProjectsSpamFiltervenvKeraslibsite-packages
umpycore
umeric.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以获取此错误的参考。
以上是关于直方图频率激活时Keras Tensorboard错误的主要内容,如果未能解决你的问题,请参考以下文章
使用 Keras 和 fit_generator 的 TensorBoard 分布和直方图
使用带有 Keras 的 TensorBoard 创建日志文件时出错
使用 TensorFlow 2.0 Alpha 时无法在 Tensorboard 中看到 keras 模型图
使用 tf.keras.Model.fit 进行训练时如何将自定义摘要添加到 tensorboard