Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras: difference of InputLayer and Input

I made a model using Keras with Tensorflow. I use Inputlayer with these lines of code:

img1 = tf.placeholder(tf.float32, shape=(None, img_width, img_heigh, img_ch))
first_input = InputLayer(input_tensor=img1, input_shape=(img_width, img_heigh, img_ch)) 
first_dense = Conv2D(16, 3, 3, activation='relu', border_mode='same', name='1st_conv1')(first_input)

But I get this error:

ValueError: Layer 1st_conv1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.engine.topology.InputLayer'>. Full input: [<keras.engine.topology.InputLayer object at 0x00000000112170F0>]. All inputs to the layer should be tensors.

When I use Input like this, it works fine:

first_input = Input(tensor=img1, shape=(224, 224, 3), name='1st_input')
first_dense = Conv2D(16, 3, 3, activation='relu', border_mode='same', name='1st_conv1')(first_input)

What is the difference between Inputlayer and Input?

like image 886
hyun woo Cho Avatar asked Sep 11 '17 01:09

hyun woo Cho


People also ask

What is input () in Keras?

In Keras, the input layer itself is not a layer, but a tensor. It's the starting tensor you send to the first hidden layer. This tensor must have the same shape as your training data. Example: if you have 30 images of 50x50 pixels in RGB (3 channels), the shape of your input data is (30,50,50,3) .

What is input layer definition?

What Does Input Layer Mean? The input layer of a neural network is composed of artificial input neurons, and brings the initial data into the system for further processing by subsequent layers of artificial neurons. The input layer is the very beginning of the workflow for the artificial neural network.

What is a Keras tensor?

Tensor. Generalization of vectors and matrices that are n-dimensional and contain the same type of data, eg. int32 or bool, etc. A Keras tensor is a TensorFlow symbolic tensor object. Tensors are the primary data structure in TensorFlow and in neural networks.


1 Answers

  • InputLayer is a layer.
  • Input is a tensor.

You can only call layers passing tensors to them.

The idea is:

outputTensor = SomeLayer(inputTensor)

So, only Input can be passed because it's a tensor.

Honestly, I have no idea about the reason for the existence of InputLayer. Maybe it's supposed to be used internally. I never used it, and it seems I'll never need it.

like image 57
Daniel Möller Avatar answered Oct 25 '22 17:10

Daniel Möller