【发布时间】: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