A Keras model can used as a Tensorflow function on a Tensor, through the functional API, as described here.
So we can do:
from keras.layers import InputL
It would seem that InputLayer
has some uses:
First, it allows you to give pure tensorflow tensors as is, without specifying their shape. E.g. you could have written
model.add(InputLayer(input_tensor=a))
This is nice for several obvious reasons, among others less duplication.
Second, they allow you to write non-sequential networks with a single input, e.g.
input
/ \
/ \
/ \
conv1 conv2
| |
Without InputLayer
you would need to explicitly feed conv1
and conv2
the same tensor, or create an arbitrary identity layer on top of the model. Neither is quite pleasing.
Finally, they remove the arbitrary distinction between "layers that are also inputs" and "normal layers". If you use InputLayer
you can write code where there is a clear distinction between what layer is the input and what layer does something. This improves code readability and makes refactoring much easier. For example, replacing the first layer becomes just as easy as replacing any other layer, you don't need to think about input_shape
.