Python Keras: An layer output exactly the same thing as input

Issue

I am using Keras to build a Network. During the process, I need a layer, which takes an LSTM input, doing nothing, just output exactly the same as input. i.e. if each input record of LSTM is like [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]], I am looking for a layer:

model.add(SomeIdentityLayer(x))

SomeIdentityLayer(x) will take [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]] as input and output [[A_t1, A_t2, A_t3, A_t4, A_t5, A_t6]]. Is such layer/structure available in Keras? Thanks!

Solution

For a simpler operation like identity, you can just use a Lambda layer like:

model.add(Lambda(lambda x: x))

This will return an output exactly the same as your input.

Answered By – Clarence Leung

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published