0

I plan to do a random projection on the outputs of the encoded and hence

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)

Added these 3 layers of zeromat, noisemat and dot_product before decoder

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)

When I run model = Model(input_img, decoded) I get this error I am unable to fix! AttributeError: 'NoneType' object has no attribute '_inbound_nodes'. How can this be fixed or done properly?

hearse
  • 379
  • 2
  • 4
  • 23

1 Answers1

0

François Chollet, keras creator implements Autoencoders as follows:


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

Hopes this inspires you. Also check this notebook

Guillem
  • 2,376
  • 2
  • 18
  • 35
  • instead of additive noise I want to multiply with a random matrix (as its random projection). can you modify for that? – hearse Aug 07 '19 at 17:29