我正在尝试根据大量txt训练模型。 2623行数字的文件。模型如下:
input_img = Input(shape=(2623,1), name='input')
x = Conv1D(32, 3, activation='relu', padding='same', use_bias=False)(input_img)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling1D(2, padding='same')(x)
x = Conv1D(16, 3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling1D(2, padding='same')(x)
x = Conv1D(16,3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x)
x = BatchNormalization(axis=-1)(x)
encoded = MaxPooling1D(2, padding='same')(x)
x = Conv1D(16,3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(encoded)
x = BatchNormalization(axis=-1)(x)
x = UpSampling1D(2)(x)
x = Conv1D(16,3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x)
x = BatchNormalization(axis=-1)(x)
x = UpSampling1D(2)(x)
x = Conv1D(32, 3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x) #input_shape=(30, 1))
x = BatchNormalization(axis=-1)(x)
x = UpSampling1D(2)(x)
decoded = Conv1D(3, 3, activation='sigmoid', padding='same', use_bias=False,input_shape=(2623,1))(x)
autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='rmsprop', loss='binary_crossentropy')
x = Input(shape=(16, 300), name="input")
h = x
h = Conv1D(filters=300, kernel_size=16,
activation="relu", padding='same', name='Conv1',input_shape=(2623,1))(h)
h = MaxPooling1D(pool_size=16, name='Maxpool1')(h)
每当我尝试使用以下代码拟合模型时,都会出现错误消息: 检查目标时出错:预计conv1d_283的形状为(2624,1),但数组的形状为(2623,1)
我尝试了不同的填充,并设置了较小的输入空间,但似乎不起作用。我没有得到错误,因为无论我做什么,最终我都会因尺寸不同而出错。有什么想法吗?
history = autoencoder.fit(train, train,
epochs=100,
batch_size=256,
shuffle=True,
validation_data=(test, test))
答案 0 :(得分:0)
感谢您的帮助。最后,最后添加了一个croplayer达到了目的,即:
x = Cropping1D(cropping=(0, 1))(x) # Crop nothing from input but crop 1 elemnt from the end