Keras-TensorBoard不保存日志文件

时间:2018-07-04 08:12:30

标签: python keras tensorboard

作为网络示例,我使用了第一个示例here

我想在该网络中使用张量板。阅读有关如何使用TensorBoard的documentation之后,我将以下命令添加到了代码中:

from keras.callbacks import TensorBoard
TensorBoard("Directory path that contains the log files")

输出听起来正确:

Out[3]: <keras.callbacks.TensorBoard at 0x7f14730e79b0>

但是目录中没有任何内容...

我做错了什么?

这是完整的代码:

import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
from keras.callbacks import TensorBoard

# Generate dummy data
import numpy as np
x_train = np.random.random((1000, 20))
y_train = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)
x_test = np.random.random((100, 20))
y_test = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)

model = Sequential()
# Dense(64) is a fully-connected layer with 64 hidden units.
# in the first layer, you must specify the expected input data shape:
# here, 20-dimensional vectors.
model.add(Dense(64, activation='relu', input_dim=20))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
              optimizer=sgd,
              metrics=['accuracy'])

model.fit(x_train, y_train,
          epochs=20,
          batch_size=128)
score = model.evaluate(x_test, y_test, batch_size=128)
TensorBoard("Directory path that contains the log files") 

1 个答案:

答案 0 :(得分:4)

您需要将回调传递给model.fit:

let documentPickerController = UIDocumentPickerViewController(documentTypes: ["com.microsoft.word.doc", "org.openxmlformats.wordprocessingml.document"], in: .import)