最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

keras.layer.input()用法說(shuō)明

 更新時(shí)間:2020年06月16日 15:23:38   作者:TinaO-O  
這篇文章主要介紹了keras.layer.input()用法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

tenserflow建立網(wǎng)絡(luò)由于先建立靜態(tài)的graph,所以沒(méi)有數(shù)據(jù),用placeholder來(lái)占位好申請(qǐng)內(nèi)存。

那么keras的layer類其實(shí)是一個(gè)方便的直接幫你建立深度網(wǎng)絡(luò)中的layer的類。

該類繼承了object,是個(gè)基礎(chǔ)的類,后續(xù)的諸如input_layer類都會(huì)繼承與layer

由于model.py中利用這個(gè)方法建立網(wǎng)絡(luò),所以仔細(xì)看一下:他的說(shuō)明詳盡而豐富。

input()這個(gè)方法是用來(lái)初始化一個(gè)keras tensor的,tensor說(shuō)白了就是個(gè)數(shù)組。他強(qiáng)大到之通過(guò)輸入和輸出就能建立一個(gè)keras模型。shape或者batch shape 必須只能給一個(gè)。shape = [None,None,None],會(huì)創(chuàng)建一個(gè)?*?*?的三維數(shù)組。

下面還舉了個(gè)例子,a,b,c都是keras的tensor, `model = Model(input=[a, b], output=c)`

def Input(shape=None, batch_shape=None,
     name=None, dtype=None, sparse=False,
     tensor=None):
  """`Input()` is used to instantiate a Keras tensor.
  A Keras tensor is a tensor object from the underlying backend
  (Theano, TensorFlow or CNTK), which we augment with certain
  attributes that allow us to build a Keras model
  just by knowing the inputs and outputs of the model.
  For instance, if a, b and c are Keras tensors,
  it becomes possible to do:
  `model = Model(input=[a, b], output=c)`
  The added Keras attributes are:
    `_keras_shape`: Integer shape tuple propagated
      via Keras-side shape inference.
    `_keras_history`: Last layer applied to the tensor.
      the entire layer graph is retrievable from that layer,
      recursively.
  # Arguments
    shape: A shape tuple (integer), not including the batch size.
      For instance, `shape=(32,)` indicates that the expected input
      will be batches of 32-dimensional vectors.
    batch_shape: A shape tuple (integer), including the batch size.
      For instance, `batch_shape=(10, 32)` indicates that
      the expected input will be batches of 10 32-dimensional vectors.
      `batch_shape=(None, 32)` indicates batches of an arbitrary number
      of 32-dimensional vectors.
    name: An optional name string for the layer.
      Should be unique in a model (do not reuse the same name twice).
      It will be autogenerated if it isn't provided.
    dtype: The data type expected by the input, as a string
      (`float32`, `float64`, `int32`...)
    sparse: A boolean specifying whether the placeholder
      to be created is sparse.
    tensor: Optional existing tensor to wrap into the `Input` layer.
      If set, the layer will not create a placeholder tensor.
  # Returns
    A tensor.
  # Example
  ```python
  # this is a logistic regression in Keras
  x = Input(shape=(32,))
  y = Dense(16, activation='softmax')(x)
  model = Model(x, y)
  ```
  """

tip:我們?cè)趍odel.py中用到了shape這個(gè)attribute,

 input_image = KL.Input(
      shape=[None, None, config.IMAGE_SHAPE[2]], name="input_image")
    input_image_meta = KL.Input(shape=[config.IMAGE_META_SIZE],
                  name="input_image_meta")

閱讀input()里面的句子邏輯:

可以發(fā)現(xiàn),進(jìn)入if語(yǔ)句的情況是batch_shape不為空,并且tensor為空,此時(shí)進(jìn)入if,用assert判斷如果shape不為空,那么久會(huì)有錯(cuò)誤提示,告訴你要么輸入shape 要么輸入batch_shape, 還提示你shape不包含batch個(gè)數(shù),就是一個(gè)batch包含多少?gòu)垐D片。

那么其實(shí)如果tensor不空的話,我們可以發(fā)現(xiàn),也會(huì)彈出這個(gè)提示,但是作者沒(méi)有寫(xiě)這種題型,感覺(jué)有點(diǎn)沒(méi)有安全感。注意點(diǎn)好了

  if not batch_shape and tensor is None:
    assert shape is not None, ('Please provide to Input either a `shape`'
                  ' or a `batch_shape` argument. Note that '
                  '`shape` does not include the batch '
                  'dimension.')

如果單純的按照規(guī)定輸入shape,舉個(gè)例子:只將shape輸入為None,也就是說(shuō)tensor的dimension我都不知道,但我知道這是個(gè)向量,你看著辦吧。

input_gt_class_ids = KL.Input(
shape=[None], name="input_gt_class_ids", dtype=tf.int32)

就會(huì)調(diào)用Input()函數(shù)中的這個(gè)判斷句式,注意因?yàn)閟hape是個(gè)List,所以shape is not None 會(huì)返回true。同時(shí)有沒(méi)有輸入batch_shape的話,就會(huì)用shape的參數(shù)去創(chuàng)造一個(gè)batch_shape.

if shape is not None and not batch_shape:
batch_shape = (None,) + tuple(shape)

比如如果輸入:

shape = (None,)
batch_shape = (None,)+shape
batch_shape
#會(huì)得到(None, None)

可以發(fā)現(xiàn),這里要求使用者至少指明你的數(shù)據(jù)維度,比如圖片的話,是三維的,所以shape至少是[None,None,None],而且我認(rèn)為shape = [None,1] 與shape = [None]是一樣的都會(huì)創(chuàng)建一個(gè)不知道長(zhǎng)度的向量。

以上這篇keras.layer.input()用法說(shuō)明就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

武夷山市| 民乐县| 卢湾区| 慈利县| 黄浦区| 溧水县| 南川市| 大洼县| 进贤县| 阿勒泰市| 巨鹿县| 二连浩特市| 昔阳县| 陇西县| 琼海市| 镇远县| 黎川县| 云安县| 新和县| 远安县| 和平区| 上思县| 罗源县| 华容县| 佛山市| 肇源县| 平昌县| 密云县| 吴川市| 尤溪县| 泸水县| 克拉玛依市| 临澧县| 渝中区| 大厂| 简阳市| 柏乡县| 太白县| 开平市| 且末县| 丹江口市|