Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Deep learning mnist情况下自动编码器模型中解码器层的定义_Deep Learning_Keras_Mnist - Fatal编程技术网

Deep learning mnist情况下自动编码器模型中解码器层的定义

Deep learning mnist情况下自动编码器模型中解码器层的定义,deep-learning,keras,mnist,Deep Learning,Keras,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) de

我试图按照中给出的示例构建自动编码器模型

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\u-input,output=decoded)
,在最初的帖子中写为
decoder=Model(input=encoded\u-input,output=decoder\u-layer(encoded\u-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: []
回溯(最近一次呼叫最后一次):
文件“train.py”,第37行,在
解码器=模型(输入=编码\输入,输出=解码)
文件“tfw/lib/python3.4/site packages/Keras-1.0.3-py3.4.egg/Keras/engine/topology.py”,第1713行,在__
str(带有完整输入的图层)
异常:图形已断开连接:无法获取“input_1”层的张量张量值(“input_1:0”,shape=(?,784),dtype=float32)。访问以下以前的层时没有问题:[]

我也遇到了同样的问题,并设法找到了一个混乱但有效的解决方案。将定义解码器的行更改为:

decoder = Model(input=encoded_input, output=autoencoder.layers[6](autoencoder.layers[5](autoencoder.layers[4](encoded_input))))
您看到的错误表明存在断开连接的图形。在这种情况下,输入张量(定义为
encoded_input
)被直接馈送到最终输出张量(定义为最终解码层)(784维的密集层)。跳过中间张量(64维和128维的密集层)。我的解决方案嵌套了这些层,以便每个层都作为下一层的输入,而最内层的张量将
编码的\u输入作为输入