TensorFlow函数:tf.keras.Input

2019-03-02 17:09 更新

tf.keras.Input函数

别名:

  • tf.keras.Input
  • tf.keras.layers.Input
tf.keras.Input(
    shape=None,
    batch_size=None,
    name=None,
    dtype=None,
    sparse=False,
    tensor=None,
    **kwargs
)

定义在:tensorflow/python/keras/_impl/keras/engine/input_layer.py.

Input()用于实例化Keras张量.

Keras张量是来自底层后端(Theano或TensorFlow)的张量对象,我们增加了某些属性,使我们能够通过了解模型的输入和输出来构建Keras模型.

例如,如果a,b和c是Keras张量,就有可能做到:model=Model(input=[a, b], output=c)

添加的Keras属性是_keras_history,应用于张量的最后一层.整个图层图可以递归地从该图层中检索.

参数:

  • shape:形状元组(整数),不包括批量大小.例如,shape=(32,),表示预期的输入将是32维向量的批次.
  • batch_size:可选的静态批量大小(整数).
  • name:图层的可选名称字符串.在模型中应该是唯一的(不要重复使用相同的名称两次).如果未提供,它将自动生成.
  • dtype:数据类型由输入预期的,作为字符串(float32,float64,int32...)
  • sparse:一个布尔值,指定是否创建占位符是稀疏的.
  • tensor:可选的现有张量包裹到Input图层中.如果设置,图层将不会创建占位符张量.
  • **kwargs:不支持的参数.

返回:

A tensor.

示例:

```python
# this is a logistic regression in Keras
x = Input(shape=(32,))
y = Dense(16, activation='softmax')(x)
model = Model(x, y)
```

可能引发的异常:

  • ValueError:在参数无效的情况下.
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号