gpt4 book ai didi

neural-network - 值错误 : Input 0 is incompatible with layer dense_6 in keras

转载 作者:行者123 更新时间:2023-12-01 23:40:06 26 4
gpt4 key购买 nike

我正在尝试按照此 link 构建深度自动编码器,但我收到了这个错误:

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)

非常感谢任何建议或评论。谢谢你。

最佳答案

关注 this回答试试:

# retrieve the last layer of the autoencoder model 
decoder_layer1 = autoencoder.layers[-3]
decoder_layer2 = autoencoder.layers[-2]
decoder_layer3 = autoencoder.layers[-1]

# create the decoder model
decoder = Model(input=encoded_input,
output=decoder_layer3(decoder_layer2(decoder_layer1(encoded_input))))

关于neural-network - 值错误 : Input 0 is incompatible with layer dense_6 in keras,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44371383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com