keras icon indicating copy to clipboard operation
keras copied to clipboard

Identity layer in Keras?

Open AdityaKane2001 opened this issue 2 years ago • 3 comments

@fchollet @qlzh727

I was trying to resolve #425 of keras-cv by simply adding a single Identity layer in the layers list in case it was empty or None.

However, there is no Identity layer in Keras and thus I had to do it using the Lambda layer. Thus, I thought it would be good to have an Identity layer in Keras as there is one in torch (nn.Identity). We can support a subset of the same (leaving out the argument insensitive part, since I think it will be a nuisance for serialization).

I will be happy to code it up if you give the go-ahead.

AdityaKane2001 avatar Jul 03 '22 10:07 AdityaKane2001

Usually single op layer can use Lambda layer or will be auto wrapped by a TFOpLayer in functional model.

Layer usually should contain a block of predefined logic and I don't think we want to add any layer that only contains single op.

qlzh727 avatar Jul 06 '22 16:07 qlzh727

@qlzh727

I see. However, I think there are valid use cases of an Identity layer. For example, keras_cv.layers.RandomChoice can contain keras.layers.Identity as one of the possible augmentations. I believe it can also be used as a placeholder in many cases.

More importantly, I believe it helps with the object-oriented style of code writing. Thus I think this would be a worthy addition.

/cc @fchollet

AdityaKane2001 avatar Jul 08 '22 07:07 AdityaKane2001

@AdityaKane2001 feel free to send a PR for this!

LukeWood avatar Aug 25 '22 17:08 LukeWood