如何使用 TensorBoard 回调和 TensorBoard 服务器?

how to use TensorBoard callback AND TensorBoard server?

keras blog autoencoder code 我正在尝试 运行 来自

的卷积自动编码代码

https://blog.keras.io/building-autoencoders-in-keras.html

from keras.layers import Input, Dense, Convolution2D, MaxPooling2D, UpSampling2D
from keras.models import Model

input_img = Input(shape=(1, 28, 28))

x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(input_img)

    x = MaxPooling2D((2, 2), border_mode='same')(x)
    x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
    x = MaxPooling2D((2, 2), border_mode='same')(x)
    x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
    encoded = MaxPooling2D((2, 2), border_mode='same')(x)

# at this point the representation is (8, 4, 4) i.e. 128-dimensional


Convolution2D(8, 3, 3, activation='relu', border_mode='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(16, 3, 3, activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Convolution2D(1, 3, 3, activation='sigmoid', border_mode='same')(x)

autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

在 运行 之后我 运行 这个代码用于训练 :

from keras.datasets import mnist
import numpy as np

(x_train, _), (x_test, _) = mnist.load_data()

x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.
x_train = np.reshape(x_train, (len(x_train), 1, 28, 28))
x_test = np.reshape(x_test, (len(x_test), 1, 28, 28))

现在我想绘制我使用回调的结果!我输入这个

tensorboard --logdir=/tmp/autoencoder

在我的终端中,它成功切换回 theano 但是当我 运行

from keras.callbacks import TensorBoard

autoencoder.fit(x_train, x_train,
                nb_epoch=50,
                batch_size=128,
                shuffle=True,
                validation_data=(x_test, x_test),
                callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])

仍然暗示不要切换回tensorflow。有人知道怎么解决吗?

RuntimeError                              Traceback (most recent call last)
<ipython-input-4-fc8458b2c2ba> in <module>()
      6                 shuffle=True,
      7                 validation_data=(x_test, x_test),
----> 8                 callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])

/home/hoda/anaconda2/lib/python2.7/site-packages/keras/callbacks.pyc in __init__(self, log_dir, histogram_freq, write_graph, write_images)
    487         super(TensorBoard, self).__init__()
    488         if K._BACKEND != 'tensorflow':
--> 489             raise RuntimeError('TensorBoard callback only works '
    490                                'with the TensorFlow backend.')
    491         self.log_dir = log_dir

RuntimeError: TensorBoard callback only works with the TensorFlow backend.

要切换到 Tensorflow 后端,您必须编辑位于 ~/.keraskeras.json 文件。

您应该会看到一行 "backend": "theano",将 "theano" 更改为 "tensorflow" 如果正确安装了 Tensorflow,它应该可以工作,并且在导入时应该会出现 "Using TensorFlow backend." 行凯拉斯