2017-09-11 23 views
1

我使用Keras和Tensorflow做了一個模型。我用Inputlayer用幾行代碼:Keras:InputLayer和Input的區別

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) 

但我得到這個錯誤:當我使用Input這樣

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. 

,它工作正常:

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) 

什麼InputlayerInput之間的區別?

回答

2
  • InputLayer是一個圖層。
  • Input是張量。

您只能調用將張量傳遞給它們的圖層。

的理念是:

outputTensor = SomeLayer(inputTensor) 

因此,只有Input可以傳遞,因爲它是一個張量。

老實說,我不知道存在InputLayer的原因。也許它應該在內部使用。我從來沒有使用它,似乎我永遠不會需要它。

+0

然而,當在Keras中創建Input並將模型序列化爲json時,Input會轉換爲InputLayer ...所以我猜測它不僅僅是內部的。不知道爲什麼。 – Jodo

相關問題