【问题标题】:problem using convolutional autoencoder for 2d data使用卷积自动编码器处理二维数据的问题
【发布时间】:2021-12-20 05:54:01
【问题描述】:

我想为 gpr 调查训练一个自动编码器。 输入数据尺寸为 149x8。但是,当我尝试深度自动编码器时,它工作正常

input_img = Input(shape=(8,))

encoded1 = Dense(8,  activation='relu')(input_img)
encoded2 = Dense(4,  activation='relu')(encoded1)
encoded3 = Dense(2,  activation='relu' )(encoded2)


decoded1 = Dense(2,  activation='relu' )(encoded3)
decoded2 = Dense(4,  activation='relu')(decoded1)
decoded3 = Dense(8,  activation='relu' )(decoded2)
decoded = Dense(8, activation='linear')(decoded3)
                
autoencoder = Model(input_img, decoded)
sgd = optimizers.Adam(lr=0.001)

autoencoder.compile(optimizer=sgd, loss='mse')

autoencoder.summary()

.................................................. ...

But while trying to use convolutional autoencoder for the same input
it  gives error `ValueError: Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=2`

谁能建议我如何克服这个问题。

我的代码是

input_img = Input(shape=(8,))

x = layers.Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = layers.MaxPooling2D((2, 2), padding='same')(x)
x = layers.Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = layers.MaxPooling2D((2, 2), padding='same')(x)
x = layers.Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = layers.MaxPooling2D((2, 2), padding='same')(x)


x = layers.Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = layers.UpSampling2D((2, 2))(x)
x = layers.Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = layers.UpSampling2D((2, 2))(x)
x = layers.Conv2D(16, (3, 3), activation='relu')(x)
x = layers.UpSampling2D((2, 2))(x)
decoded = layers.Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)

autoencoder = Model(input_img, decoded)
sgd = optimizers.Adam(lr=0.001)

autoencoder.compile(optimizer=sgd, loss='mse')

autoencoder.summary()

【问题讨论】:

    标签: tensorflow keras deep-learning autoencoder encoder


    【解决方案1】:

    错误的输入形状:

    这是因为我们传递了 (8,) 的输入形状和 TensorFlow 为 Batch 大小添加的 1 个额外维度,因此错误消息说它找到 ndim=3,但 CNN 已预期 min_ndim=4, 3图像大小和批量大小为 1。例如

    input_shape=(number_of_rows, 28,28,1)
    

    【讨论】:

    • 我总是必须使用 28,28,1
    猜你喜欢
    • 2021-04-18
    • 1970-01-01
    • 2020-08-20
    • 2018-07-15
    • 2020-02-11
    • 2018-11-12
    • 1970-01-01
    • 2017-02-24
    • 2022-11-29
    相关资源
    最近更新 更多