I have a Siamese neural network and I want to apply a linear transformation on the extracted image feature to reduce the dimensionality using PCA or autoencoders. how can I implement it after the flatten layer?
this is my code:
input_a = Input(shape=(input_shape))
input_b = Input(shape=(input_shape))
# Convolutional Neural NetworK
seq = Sequential()
seq.add(Conv2D(32, (5,5), activation='relu',padding='same',input_shape=input_shape,
kernel_initializer=initializers.RandomNormal(mean=0.0 ,stddev=0.1, seed=None),bias_initializer= initializers.Zeros()))
seq.add(MaxPooling2D(pool_size=(2,2) ,strides=(2,2)))
seq.add(Conv2D(64, (5,5), activation='relu',padding='same',
kernel_initializer=initializers.RandomNormal(mean=0.0 ,stddev=0.1, seed=None),bias_initializer= initializers.Zeros()))
seq.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
seq.add(Flatten())
processed_a = seq(input_a)
processed_b = seq(input_b)
#here i want to preform linear transformation
L2_distance = Lambda(euclidean_distance, output_shape=eucl_dist_output_shape,name='L2')([processed_a, processed_b])
a = Lambda(function,output_shape=eucl_dist_output_shape,name='out1')(L2_distance)
model = Model([input_a, input_b],a)
For adding a linear transformation layer at the end of a Siamese Neural Network, or better say its encoder, you can do the following two steps: