Keras中的卷积自动编码器解码器错误



我正试图训练一个卷积自动编码器来重建80X130 的图像

我已经添加了所有必要的导入,我正在用python 3.7 编写它

这是我得到的错误:

Traceback(最后一次调用(:

文件"CAED_Keras.py",第52行,在中validation_data=(x_train,x_train((,拟合

文件"C:\Python37\lib\site-packages\keras\engine\training.py",第1154行,在fit-in_standardize_user_data中batch_size=batch_size(

文件"C:\Python37\lib\site-packages\keras\engine\training.py",第621行,e 145,在_standardize_user_data中的standardize_input_data中exception_prefix='target'(,76,1(,但得到形状为(1,80130(的数组

文件"C:\Python37\lib\site packages\keras\engine\training_utils.py",第145行,在standardize_input_data中str(data_shape((

ValueError:检查目标时出错:要求conv2d_7具有形状(4,76,1(,但得到的数组具有形状(180130(

这是我的代码:

input_img = Input(shape=(80, 130, 1)) 
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
#Load Data
x_train = np.copy(lt.mel_spect_out[:int(len(lt.mel_spect_out)/10*9)])
x_test = np.copy(lt.mel_spect_out[int(len(lt.mel_spect_out)/10*9):])
#normalize
x_train = x_train / 255.
x_test = x_test / 255.

x_train = np.reshape(x_train, (len(x_train), 80, 130, 1))  
x_test = np.reshape(x_test, (len(x_test), 80, 130, 1))  
autoencoder.fit(x_train, x_train,
epochs=50,
batch_size=30,
shuffle=True,
validation_data=(x_train, x_train))

您有几个问题:

网络的体系结构

我改变了一些事情:首先,我在编码层之后添加了一个UpSampling层,并删除了最后一个层以保持对称性。然后,我将padding='same'添加到最后16个过滤器conv层中,以防止数据被"裁剪"。

这是生成的代码:

x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
x = UpSampling2D((2, 2))(encoded)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu', padding='same')(x)
decoded = Conv2D(1, (3, 3), activation='relu', padding='same')(x)

输入形状

这里的问题是,您想要对数据进行3次下采样。

第一个维度没有问题:80 % 2^3 = 0

但对于第二个:130 % 2^3 = 2,这是有问题的。

你能做什么

  • 您可以将图像的高度裁剪为128
  • 我现在没有其他想法

最后一个音符

您使用了

validation_data=(x_train, x_train)

相关内容

  • 没有找到相关文章

最新更新