一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - keras.layer.input()用法說明

keras.layer.input()用法說明

2020-06-17 11:00TinaO-O Python

這篇文章主要介紹了keras.layer.input()用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

tenserflow建立網絡由于先建立靜態的graph,所以沒有數據,用placeholder來占位好申請內存。

那么keras的layer類其實是一個方便的直接幫你建立深度網絡中的layer的類。

該類繼承了object,是個基礎的類,后續的諸如input_layer類都會繼承與layer

由于model.py中利用這個方法建立網絡,所以仔細看一下:他的說明詳盡而豐富。

input()這個方法是用來初始化一個keras tensor的,tensor說白了就是個數組。他強大到之通過輸入和輸出就能建立一個keras模型。shape或者batch shape 必須只能給一個。shape = [None,None,None],會創建一個?*?*?的三維數組。

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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:我們在model.py中用到了shape這個attribute,

?
1
2
3
4
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()里面的句子邏輯:

可以發現,進入if語句的情況是batch_shape不為空,并且tensor為空,此時進入if,用assert判斷如果shape不為空,那么久會有錯誤提示,告訴你要么輸入shape 要么輸入batch_shape, 還提示你shape不包含batch個數,就是一個batch包含多少張圖片。

那么其實如果tensor不空的話,我們可以發現,也會彈出這個提示,但是作者沒有寫這種題型,感覺有點沒有安全感。注意點好了

?
1
2
3
4
5
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.')

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

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

就會調用Input()函數中的這個判斷句式,注意因為shape是個List,所以shape is not None 會返回true。同時有沒有輸入batch_shape的話,就會用shape的參數去創造一個batch_shape.

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

比如如果輸入:

?
1
2
3
4
shape = (None,)
batch_shape = (None,)+shape
batch_shape
#會得到(None, None)

可以發現,這里要求使用者至少指明你的數據維度,比如圖片的話,是三維的,所以shape至少是[None,None,None],而且我認為shape = [None,1] 與shape = [None]是一樣的都會創建一個不知道長度的向量。

以上這篇keras.layer.input()用法說明就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/u013249853/article/details/88950943

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产欧美日韩不卡 | 奇米狠狠色 | 边摸边吃奶边做爽视频免费 | 大学第一次基本都没了 | 免费在线公开视频 | 乌克兰一级片 | 亚洲九九九| 91视频国产精品 | 黑人巨| 激情综 | 日本免费高清在线 | 修修视频在线观看 | 国模大胆一区二区三区 | 男女肉粗暴进来下面好紧 | 国产精品亚洲综合久久 | 国产成人夜色影视视频 | 亚洲成a人不卡在线观看 | 欧美日韩导航 | vod国产成人精品视频 | brazzersxxx欧美 | 99视频在线观看视频一区 | 香蕉eeww99国产精选播放 | 国产一区二区三区福利 | 日本 视频 在线 | 日本成人黄色网址 | 国产成人久久精品一区二区三区 | 国产探花在线视频 | 扒开黑女人p大荫蒂老女人 扒开大腿狠狠挺进视频 | 2021最新国产成人精品免费 | 人妖巨茎video | 国产好痛疼轻点好爽的视频 | 和肥岳在厨房激情 | 车上小婕子系列辣文小说 | ipx 在线播放 | a级毛片毛片免费很很综合 a级黄色视屏 | 国产在线精品99一卡2卡 | 魔镜号中文字幕 | 国产福利兔女郎在线观看 | 日本免费的一级绿象 | 日韩在线毛片 | 日韩欧美在线一区二区三区 |