Tôi đang cố gắng theo Bộ mã hóa tự động sâu Két example. Tôi nhận được một ngoại lệ không khớp, nhưng đối với cuộc sống của tôi, tôi không thể hiểu tại sao. Nó hoạt động khi tôi chỉ sử dụng một kích thước được mã hóa, nhưng không phải khi tôi xếp chúng.Python/Keras/Theano sai kích thước cho bộ mã hóa tự động sâu
Ngoại lệ: Input 0 là không phù hợp với lớp dense_18:
hình dự kiến = (Không, 128), tìm thấy hình = (Không, 32) *
Lỗi này là trên dòng decoder = Model(input=encoded_input, output=decoder_layer(encoded_input))
from keras.layers import Dense,Input
from keras.models import Model
import numpy as np
# this is the size of the encoded representations
encoding_dim = 32
#NPUT LAYER
input_img = Input(shape=(784,))
#ENCODE LAYER
# "encoded" is the encoded representation of the input
encoded = Dense(encoding_dim*4, activation='relu')(input_img)
encoded = Dense(encoding_dim*2, activation='relu')(encoded)
encoded = Dense(encoding_dim, activation='relu')(encoded)
#DECODED LAYER
# "decoded" is the lossy reconstruction of the input
decoded = Dense(encoding_dim*2, activation='relu')(encoded)
decoded = Dense(encoding_dim*4, activation='relu')(decoded)
decoded = Dense(784, activation='sigmoid')(decoded)
#MODEL
autoencoder = Model(input=input_img, output=decoded)
#SEPERATE ENCODER MODEL
encoder = Model(input=input_img, output=encoded)
# create a placeholder for an encoded (32-dimensional) input
encoded_input = Input(shape=(encoding_dim,))
# retrieve the last layer of the autoencoder model
decoder_layer = autoencoder.layers[-1]
# create the decoder model
decoder = Model(input=encoded_input, output=decoder_layer(encoded_input))
#COMPILER
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
Thật tuyệt vời khi hầu hết mọi người đấu tranh ở cùng một điểm. Cảm ơn bạn đã chia sẻ –
https://stackoverflow.com/questions/47842931/valueerror-error-when-checking-target-expected-model-2-to-have-shape-none-25 bất kỳ đề xuất nào? –