【问题标题】:how to use TensorBoard callback AND TensorBoard server?如何使用 TensorBoard 回调和 TensorBoard 服务器?
【发布时间】:2017-02-27 15:04:23
【问题描述】:

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,您做了什么?
  • 是的,您似乎从未真正切换过后端。添加 TensorBoard 回调并不会自行更改后端。
  • 我在终端输入了 $ tensorboard --logdir=/tmp/autoencoder !你可能是对的。我该如何将其更改为张量流?部分代码可以在 theano 上运行,其余部分在 tensorflow 上运行吗?
  • 在哪里输入 tensorboard 命令,tensorboard --logdir=/tmp/autoencoder 。根据我的理解,我必须在命令提示符下输入,但这给出了错误“tensorboard”不被识别为内部或外部命令、可运行程序或批处理文件。”

标签: tensorflow theano keras tensorboard autoencoder


【解决方案1】:

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

您应该会看到一行 "backend": "theano",将“theano”更改为“tensorflow”,如果正确安装了 Tensorflow,它应该可以工作,并且该行“使用 TensorFlow 后端”。导入 Keras 时应该会出现。

【讨论】:

  • 如何在 theano 上训练我的模型,然后使用张量流读取日志并使用 TensorBoard 回调? link
  • 我很确定不可能使用 Theano 和 Tensorboard 回调
  • 确实不可能做到这一点。如果你想要张量板,请使用 tf 后端。它必须在后端创建 TF 对象才能使其工作。
猜你喜欢
  • 2017-06-26
  • 2016-10-04
  • 2020-01-23
  • 2016-10-25
  • 2018-01-09
  • 2020-01-25
  • 2020-04-06
  • 2018-09-16
  • 2019-08-30
相关资源
最近更新 更多