我使用带有Tensorflow的Keras制作了模型。我使用Inputlayer以下代码行:
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)
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误:
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.
Run Code Online (Sandbox Code Playgroud)
当我这样使用时Input,它可以正常工作:
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)
Run Code Online (Sandbox Code Playgroud)
Inputlayer和之间有什么区别Input?
输入:用于创建功能模型
inp=tf.keras.Input(shape=[?,?,?])
x=layers.Conv2D(.....)(inp)
Run Code Online (Sandbox Code Playgroud)
输入层:用于创建顺序模型
x=tf.keras.Sequential()
x.add(tf.keras.layers.InputLayer(shape=[?,?,?]))
Run Code Online (Sandbox Code Playgroud)
另一个区别是
当将InputLayer与Keras Sequential模型一起使用时,可以通过将input_shape参数移动到InputLayer之后的第一层来跳过它。
也就是说,在顺序模型中,您可以跳过输入层并直接在第一层中指定形状。即从此
model = tf.keras.Sequential([
tf.keras.layers.InputLayer(input_shape=(4,)),
tf.keras.layers.Dense(8)])
Run Code Online (Sandbox Code Playgroud)
对此
model = tf.keras.Sequential([
tf.keras.layers.Dense(8, input_shape=(4,))])
Run Code Online (Sandbox Code Playgroud)
InputLayer 是一层。 Input 是张量。 您只能调用将张量传递给它们的图层。
这个想法是:
outputTensor = SomeLayer(inputTensor)
Run Code Online (Sandbox Code Playgroud)
因此,只能Input通过,因为它是张量。
老实说,我不知道存在的原因InputLayer。也许应该在内部使用。我从未使用过它,而且似乎永远也不需要它。
| 归档时间: |
|
| 查看次数: |
1360 次 |
| 最近记录: |