What is the advantage of using an InputLayer (or an Input) in a Keras model with Tensorflow tensors?

后端 未结 1 971
滥情空心
滥情空心 2021-01-31 19:21

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         


        
相关标签:
1条回答
  • 2021-01-31 19:51

    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.

    0 讨论(0)
提交回复
热议问题