喀拉拉邦编码器后的随机投影

时间:2019-08-07 16:40:07

标签: keras projection keras-layer autoencoder tf.keras

我计划对编码后的输出进行随机投影,因此

input_img = Input(shape=(32, 32, 3))
x = Conv2D(64, (3, 3), padding='same')(input_img)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), padding='same')(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(16, (3, 3), padding='same')(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
  

在解码器之前添加了这三层零垫,噪声垫和dot_product

zeromat = tf.keras.backend.zeros(shape=tf.keras.backend.shape(encoded))
    noisemat = ErrorProp(1)(zeromat)
    dot_product = Multiply()([encoded, noisemat])  

    x = Conv2D(16, (3, 3), padding='same')(dot_product)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = UpSampling2D((2, 2))(x)
    x = Conv2D(32, (3, 3), padding='same')(x)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = UpSampling2D((2, 2))(x)
    x = Conv2D(64, (3, 3), padding='same')(x)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = UpSampling2D((2, 2))(x)
    x = Conv2D(3, (3, 3), padding='same')(x)
    x = BatchNormalization()(x)
    decoded = Activation('sigmoid')(x)
  

当我运行模型=模型(input_img,已解码)时,出现此错误   无法修复! AttributeError:“ NoneType”对象没有属性   '_inbound_nodes'。该如何解决或正确完成?

1 个答案:

答案 0 :(得分:0)

keras创作者FrançoisChollet实现了自动编码器,如下所示:


img_shape = (28, 28, 1)
batch_size = 16
latent_dim = 2  # Dimensionality of the latent space: a plane

input_img = keras.Input(shape=img_shape)

# Start encoder
x = layers.Conv2D(32, 3,
                  padding='same', activation='relu')(input_img)
x = layers.Conv2D(64, 3,
                  padding='same', activation='relu',
                  strides=(2, 2))(x)
x = layers.Conv2D(64, 3,
                  padding='same', activation='relu')(x)
x = layers.Conv2D(64, 3,
                  padding='same', activation='relu')(x)
shape_before_flattening = K.int_shape(x)

x = layers.Flatten()(x)
x = layers.Dense(32, activation='relu')(x)
# end encode

# Start random noise adder
z= layers.Dense(latent_dim)(x)


def add_random_noise(z):
    return z + K.random_uniform(shape=K.shape(z), low=0, high=1)

z_with_noise = layers.Lambda(add_random_noise)(z)
# End of random noise adder

## Continue with decoder

希望这会激发您的灵感。还要检查此notebook