tensorflowkeraslstmkeras-layerkeras-2

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


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.