直方图频率激活时的 Keras Tensorboard 错误
Posted
技术标签:
【中文标题】直方图频率激活时的 Keras Tensorboard 错误【英文标题】:Keras Tensorboard Error when Histogram Frequency active 【发布时间】:2018-10-12 10:30:29 【问题描述】:当我尝试使用 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
时,我没有收到错误,但我想获取直方图信息,有人可以帮我找出原因吗?
【问题讨论】:
【参考方案1】:在创建模型之前尝试运行K.clear_session()
。
请参阅此GitHub thread 以了解此错误。
【讨论】:
【参考方案2】:这可能与K.learing_phase()
有关。特别是如果你之前做过K.set_learning_phase(1)
。
诊断:
运行print(K.learning_phase())
,如果它返回一个int,那么这个问题几乎肯定与这个问题有关。尝试删除所有与K.set_learing_phase(1)
相关的句子,看看是否有所不同。
【讨论】:
以上是关于直方图频率激活时的 Keras Tensorboard 错误的主要内容,如果未能解决你的问题,请参考以下文章