I am trying to implement AUTOENCODER with skip connections and split the Encoder and Decoder parts. So, I can work on latent space and Decoder part. Below is the architecture in keras I used:
## ENCODER
inputs_encoder = Input(shape = (256, 642))
C1 = Conv1D(filters=512, kernel_size=5, padding='same', activation='relu', name='C1')(inputs_encoder)
D1 = AvgPool1D(pool_size=2)(C1)
C2 = Conv1D(filters=256, kernel_size=5, padding='same', activation='relu', name='C2')(D1)
D2 = AvgPool1D(pool_size=2)(C2)
C3 = Conv1D(filters=128, kernel_size=5, padding='same', activation='relu', name='C3')(D2)
D3 = AvgPool1D(pool_size=2)(C3)
C4 = Conv1D(filters=64, kernel_size=5, padding='same', activation='relu', name='C4')(D3)
F = Flatten()(C4)
outputs = Dense(32, activation="relu")(F)
UNet_encoder = Model(inputs_encoder, [outputs, C1, C2, C3, C4], name='UNet_encoder')
## DECODER
inputs_decoder = Input(shape=(32))
C1 = Input(shape=(256, 512))
C2 = Input(shape=(128, 256))
C3 = Input(shape=(64, 128))
C4 = Input(shape=(32, 64))
X = Dense(2048, activation='relu')(inputs_decoder)
X = Reshape(target_shape=(32, 64))(X)
C5 = Conv1D(filters=64, kernel_size=5, padding='same', activation='relu', name='C5')(X)
C5 = Concatenate(axis=-1)([C4, C5])
U = UpSampling1D(size = 2)(C5)
C6 = Conv1D(filters=128, kernel_size=5, padding='same', activation='relu', name='C6')(U)
C6 = Concatenate(axis=-1)([C3, C6])
U = UpSampling1D(size = 2)(C6)
C7 = Conv1D(filters=128, kernel_size=5, padding='same', activation='relu', name='C7')(U)
C7 = Concatenate(axis=-1)([C2, C7])
U = UpSampling1D(size = 2)(C7)
C8 = Conv1D(filters=128, kernel_size=5, padding='same', activation='relu', name='C8')(U)
C8 = Concatenate(axis=-1)([C1, C8])
outputs = Conv1D(filters=642, kernel_size=5, padding='same', activation='linear')(C8)
UNet_decoder = Model([inputs_decoder, C1, C2, C3, C4], outputs, name='UNet_decoder')
## AUTOENCODER with skip conncetions
Autoencoder_input = Input(shape = (256,642))
encoder = UNet_encoder(Autoencoder_input)
decoder = UNet_decoder(encoder)
Autoencoder = Model(Autoencoder_input, decoder)
Autoencoder.compile(optimizer=keras.optimizers.Adam(learning_rate=0.001), loss='mse')
Now, I want to make predictions for latent size input (i.e. 32 here). But Decoder part asks for skip connections C1, C2, C3 and C4. How to get rid of this issue?
decoder_input = (100,32) # samples, latent_size
pred_results = UNet_decoder.predict([decoder_input, C1, C2, C3, C4])
But I am getting followint error:
ValueError: Data cardinality is ambiguous:
x sizes: 100, 2000, 2000, 2000, 2000
Please provide data which shares the same first dimension.
Here 2000 are number of samples used in training.