ValueError: Dimensions must be equal, but are 512 and 1024

ValueError: Dimensions must be equal, but are 512 and 1024

我正在尝试构建一个简单的 auto encoder 模型(输入来自 cfar10)。

    hiden_size1 = 1024
    hiden_size2 = 512
    hiden_size3 = 1024

    input_layer = Input(shape=(3072,))
    decoder_input_layer = Input(shape=(hiden_size2,))
    hidden_layer1 = Dense(hiden_size1, activation="relu", name="hidden1")
    hidden_layer2 = Dense(hiden_size2, activation="relu", name="hidden2")
    hidden_layer3 = Dense(hiden_size3, activation="relu", name="hidden3")
    autoencoder_output_layer = Dense(3072, activation="sigmoid", name="output")


    autoencoder = Sequential()
    autoencoder.add(input_layer)
    autoencoder.add(hidden_layer1)
    autoencoder.add(hidden_layer2)
    autoencoder.add(hidden_layer3)
    autoencoder.add(autoencoder_output_layer)
    autoencoder.compile(optimizer='adam', loss='binary_crossentropy')

    encoder = Sequential()
    encoder.add(input_layer)
    encoder.add(hidden_layer1)
    encoder.add(hidden_layer2)

    decoder = Sequential()
    decoder.add(decoder_input_layer)
    encoder.add(hidden_layer3)
    decoder.add(autoencoder_output_layer)

我在最后一行代码 (decoder.add(autoencoder_output_layer)) 上遇到错误:

ValueError: Dimensions must be equal, but are 512 and 1024 for '{{node output/MatMul}} = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false](Placeholder, output/MatMul/ReadVariableOp)' with input shapes: [?,512], [1024,3072].

出了什么问题,我错过了什么?我该如何解决?

I think in the second last line , instead of

    encoder.add(hidden_layer3) 

it will be

   decoder.add(hidden_layer3)