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: []