ValueError:输入0与keras中的layer_deny_6不兼容 [英] ValueError: Input 0 is incompatible with layer dense_6 in keras

查看:1133
本文介绍了ValueError:输入0与keras中的layer_deny_6不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过遵循此链接,但出现此错误:

I am trying to build a deep autoencoder by following this link, but I got this error:

ValueError:输入0与图层density_6不兼容:预期轴 输入形状-1的值为128但形状为(None,32)

ValueError: Input 0 is incompatible with layer dense_6: expected axis -1 of input shape to have value 128 but got shape (None, 32)

代码:

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) #decode.shape = (?,128)
decoded = Dense(784, activation='relu')(decoded)

autoencoder = Model(input_img, decoded)

encoder = Model(input_img, encoded)
encoded_input = Input(shape=(encoding_dim,))
decoder_layer = autoencoder.layers[-1]
decoder = Model(encoded_input, decoder_layer(encoded_input)) #ERROR HERE
...

这是我得到的错误:

Traceback (most recent call last):
  File "autoencoder_deep.py", line 37, in <module>
    decoder = Model(encoded_input, decoder_layer(encoded_input))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/keras/engine/topology.py", line 569, in __call__
    self.assert_input_compatibility(inputs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/keras/engine/topology.py", line 479, in assert_input_compatibility
    ' but got shape ' + str(x_shape))
ValueError: Input 0 is incompatible with layer dense_6: expected axis -1 of input shape to have value 128 but got shape (None, 32)

任何建议或评论都将不胜感激.谢谢.

Any suggestion or comment is greatly appreciated. Thank you.

推荐答案

跟随 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆