2
我想按照这个link打造深的自动编码层dense_6不相容的,但我得到这个错误:ValueError异常:输入0是在keras
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)
任何建议或意见是极大的赞赏。谢谢。
您可以检查您的keras配置文件中定义的input_shape。详细信息可以在这篇文章中找到https://stackoverflow.com/questions/40135370/keras-getting-wrong-output-shape/40137162#40137162 – pyan