[英]Keras Tensorboard Error when Histogram Frequency active
I am running a simple Neural Network with Keras, backend Tensorflow, when trying to use Tesorboard to monitor training. 当尝试使用Tesorboard监视培训时,我正在使用Keras(后端Tensorflow)运行一个简单的神经网络。
My model is the following: 我的模型如下:
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'])
I try to run it using the following configuration: 我尝试使用以下配置运行它:
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])
However for some reason I get the following error: 但是由于某种原因,我得到以下错误:
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.
When I set the TensorBoard
option histogram_freq=0
I don't get the error, but I want to get the histogram information can someone help me find the reason for this? 当我设置
TensorBoard
选项histogram_freq=0
我没有得到错误,但是我想获取直方图信息,有人可以帮助我找到原因吗?
Try running K.clear_session()
before creating your model. 在创建模型之前,请尝试运行
K.clear_session()
。
See this GitHub thread for reference to this error. 请参阅此GitHub线程以参考此错误。
This may be related to K.learing_phase()
. 这可能与
K.learing_phase()
。 Especially if you have done K.set_learning_phase(1)
before. 特别是如果您之前已完成
K.set_learning_phase(1)
。
To diagnose: Run print(K.learning_phase())
, if it returns an int, then this problem is almost surely related to this issue. 要诊断:运行
print(K.learning_phase())
,如果它返回一个int值,那么这个问题几乎肯定与这个问题有关。 Try removing all sentences related to K.set_learing_phase(1)
and see if it makes a difference. 尝试删除所有与
K.set_learing_phase(1)
相关的句子,看看是否有区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.