我计划对编码的输出进行随机投影,因此
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)
在解码器之前添加了这 3 层零垫、噪声垫和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,解码(时,我收到此错误 无法修复!属性错误:"NoneType"对象没有属性 "_inbound_nodes"。如何修复或正确完成此操作?
François Chollet,keras creator 实现自动编码器,如下所示:
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
希望这能激励你。另请查看此笔记本