运算输入和计算的输入梯度之间的形状不兼容

时间:2020-09-21 14:14:00

标签: python numpy tensorflow machine-learning keras

在优化步骤之前,该模型运行良好。但是,当我要优化模型时,会出现错误消息:

ValueError:运算输入和计算输入之间的形状不兼容 梯度。正向操作: encoder_27 / quantization_layer_13 / IdentityN。输入索引:1.原始 输入形状:(?,32)。计算的输入渐变形状:()

以下是我的代码。

# parameters
feedback_bits = 128
img_height = 16
img_width = 32
img_channels = 2

# Model construction
# encoder model
Encoder_input = keras.Input(shape=(img_height, img_width, img_channels), name="encoder_input")
Encoder_output = Encoder(Encoder_input, feedback_bits)
encoder = keras.Model(inputs=Encoder_input, outputs=Encoder_output, name='encoder')

# decoder model
Decoder_input = keras.Input(shape=(feedback_bits,), name='decoder_input')
Decoder_output = Decoder(Decoder_input, feedback_bits)
decoder = keras.Model(inputs=Decoder_input, outputs=Decoder_output, name="decoder")

# autoencoder model
autoencoder_input = keras.Input(shape=(img_height, img_width, img_channels), name="original_img")
encoder_out = encoder(autoencoder_input)
decoder_out = decoder(encoder_out)
autoencoder = keras.Model(inputs=autoencoder_input, outputs=decoder_out, name='autoencoder')
autoencoder.compile(optimizer='adam', loss='mse')
print(autoencoder.summary())

# Data loading
data_load_address = './data'
mat = h5py.File(data_load_address+'/Hdata.mat', 'r')
data = np.transpose(mat['H_train'])      # shape=(320000, 1024)
data = data.astype('float32')
data1 = np.reshape(data, [len(data), img_height,  img_width, img_channels])
x_train, x_test = sklearn.model_selection.train_test_split(data1, test_size=0.05, random_state=1)
#train
autoencoder.fit(x=x_train, y=x_train, batch_size=512, epochs=1000, validation_split=0.1)



0 个答案:

没有答案