我在Keras博客中按照Keras中构建自动编码器的步骤编写程序,但它的错误如下:


    callbacks=[TensorBoard(log_dir='/Users/lyj/Programs/KiseliuGit/DeepLearning/tmp/autoencoder')])
  File "/Library/Python/2.7/site-packages/keras/callbacks.py", line 457, in __init__
raise Exception('TensorBoard callback only works '
Exception: TensorBoard callback only works with the TensorFlow backend.

为什么?我完全按照步骤做了,下面是我的程序:

#coding:utf-8
from keras.layers import Input, Dense, Convolution2D, MaxPooling2D, UpSampling2D
from keras.models import Model
from keras.datasets import mnist
import numpy as np
from keras.callbacks import TensorBoard
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)
x = 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')
(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))
autoencoder.fit(x_train, x_test, nb_epoch=50, batch_size=128, shuffle=True,validation_data=(x_test, x_test),
            callbacks=[TensorBoard(log_dir='/Users/kiseliu/DeepLearning/tmp/autoencoder')])

在我运行这个程序之前,我在cmd工具中输入命令"tensorboard——logdir=/Users/kiseliu/DeepLearning/tmp/autoencoder"。

将后端keras从.keras更改为.keras。json文件

相关内容

  • 没有找到相关文章

最新更新