2
我正在试图按照this blog中给出的示例构建autoencoder模型。mnist案例的自动编码器模型中解码器层的定义
input_img = Input(shape=(784,))
encoded = Dense(128, activation='relu')(input_img)
encoded = Dense(64, activation='relu')(encoded)
encoded = Dense(32, activation='relu')(encoded)
decoded = Dense(64, activation='relu')(encoded)
decoded = Dense(128, activation='relu')(decoded)
decoded = Dense(784, activation='sigmoid')(decoded)
# this model maps an input to its reconstruction
autoencoder = Model(input=input_img, output=decoded)
encoded_input = Input(shape=(encoding_dim,))
decoder_layer = autoencoder.layers[-1]
decoder = Model(input=encoded_input, output=decoded)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
我所做的修改是decoder = Model(input=encoded_input, output=decoded)
,这是在原来的职位写为decoder = Model(input=encoded_input, output=decoder_layer(encoded_input))
。以前的版本适用于单个隐藏层。这就是我做出上述修改的原因。但是,编译上述模型会提供以下错误消息。任何建议,高度赞赏。
Traceback (most recent call last):
File "train.py", line 37, in <module>
decoder = Model(input=encoded_input, output=decoded)
File "tfw/lib/python3.4/site-packages/Keras-1.0.3-py3.4.egg/keras/engine/topology.py", line 1713, in __init__
str(layers_with_complete_input))
Exception: Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(?, 784), dtype=float32) at layer "input_1". The following previous layers were accessed without issue: []