【问题标题】:random projection after encoder in keraskeras中编码器后的随机投影
【发布时间】:2019-08-07 16:40:07
【问题描述】:

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

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)

在decoder之前添加了zeromat、noisemat和dot_product这3层

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)

当我运行 model = Model(input_img, decoded) 时,我收到了这个错误 无法修复! AttributeError:“NoneType”对象没有属性 '_inbound_nodes'。如何解决或正确完成此问题?

【问题讨论】:

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


    【解决方案1】:

    François Chollet,keras 创建者实现自动编码器如下:

    
    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

    【讨论】:

    • 我想与一个随机矩阵相乘(作为它的随机投影),而不是加性噪声。你可以为此修改吗?
    猜你喜欢
    • 2011-11-20
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    相关资源
    最近更新 更多