甲Keras模型可以用作一个张量一个Tensorflow功能,通过所述功能API,如所描述这里.
所以我们可以这样做:
from keras.layers import InputLayer
a = tf.placeholder(dtype=tf.float32, shape=(None, 784))
model = Sequential()
model.add(InputLayer(input_tensor=a, input_shape=(None, 784)))
model.add(Dense(32, activation='relu'))
model.add(Dense(10, activation='softmax'))
output = model.output
Run Code Online (Sandbox Code Playgroud)
这是一个张量:
<tf.Tensor 'dense_24/Softmax:0' shape=(?, 10) dtype=float32>
Run Code Online (Sandbox Code Playgroud)
但是,这也没有任何作用InputLayer:
a = tf.placeholder(dtype=tf.float32, shape=(None, 784))
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(784,)))
model.add(Dense(10, activation='softmax'))
output = model(a)
Run Code Online (Sandbox Code Playgroud)
工作,并output具有与以前相同的形状:
<tf.Tensor 'sequential_9/dense_22/Softmax:0' shape=(?, 10) dtype=float32>
Run Code Online (Sandbox Code Playgroud)
我假设第一种形式允许:
inputs和outputs作为模型(相同名称)的属性,因此我们可以在其他地方重用它们.例如与其他TF操作._keras_history在所述源代码中).但这不是我们不能用第二种形式做的事情,所以,是否有特殊用法InputLayer(和Input一个更好的)(除了多个输入)?
此外,这InputLayer很棘手,因为它input_shape与其他keras层的使用方式不同:我们指定批量大小( …
我使用带有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?