[TensorFolow]函數(shù): tf.nn.conv2d

  def conv2d(input, filter, strides, padding, use_cudnn_on_gpu=True, data_format="NHWC", name=None):

r"""Computes a 2-D convolution given 4-D input and filter tensors.

Given an input tensor of shape [batch, in_height, in_width, in_channels]
and a filter / kernel tensor of shape
[filter_height, filter_width, in_channels, out_channels], this op
performs the following:

  1. Flattens the filter to a 2-D matrix with shape
    [filter_height * filter_width * in_channels, output_channels].
  2. Extracts image patches from the input tensor to form a virtual
    tensor of shape [batch, out_height, out_width, filter_height * filter_width * in_channels].
  3. For each patch, right-multiplies the filter matrix and the image patch
    vector.

In detail, with the default NHWC format,

  output[b, i, j, k] =
      sum_{di, dj, q} input[b, strides[1] * i + di, strides[2] * j + dj, q] *
                      filter[di, dj, q, k]

Must have strides[0] = strides[3] = 1. For the most common case of the same
horizontal and vertices strides, strides = [1, stride, stride, 1].

Args:
input: A Tensor. Must be one of the following types: half, float32.
A 4-D tensor. The dimension order is interpreted according to the value
of data_format, see below for details.
filter: A Tensor. Must have the same type as input.
A 4-D tensor of shape
[filter_height, filter_width, in_channels, out_channels]
strides: A list of ints.
1-D tensor of length 4. The stride of the sliding window for each
dimension of input. The dimension order is determined by the value of
data_format, see below for details.
padding: A string from: "SAME", "VALID".
The type of padding algorithm to use.
use_cudnn_on_gpu: An optional bool. Defaults to True.
data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
Specify the data format of the input and output data. With the
default format "NHWC", the data is stored in the order of:
[batch, height, width, channels].
Alternatively, the format could be "NCHW", the data storage order of:
[batch, channels, height, width].
name: A name for the operation (optional).

Returns:
A Tensor. Has the same type as input.
A 4-D tensor. The dimension order is determined by the value of
data_format, see below for details.
"""

  if not isinstance(strides, (list, tuple)):
    raise TypeError(
        "Expected list for 'strides' argument to "
        "'conv2d' Op, not %r." % strides)
  strides = [_execute.make_int(_i, "strides") for _i in strides]
  padding = _execute.make_str(padding, "padding")
  if use_cudnn_on_gpu is None:
    use_cudnn_on_gpu = True
  use_cudnn_on_gpu = _execute.make_bool(use_cudnn_on_gpu, "use_cudnn_on_gpu")
  if data_format is None:
    data_format = "NHWC"
  data_format = _execute.make_str(data_format, "data_format")
  _ctx = _context.context()
  if _ctx.in_graph_mode():
    _, _, _op = _op_def_lib._apply_op_helper(
        "Conv2D", input=input, filter=filter, strides=strides,
        padding=padding, use_cudnn_on_gpu=use_cudnn_on_gpu,
        data_format=data_format, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "strides", _op.get_attr("strides"),
              "use_cudnn_on_gpu", _op.get_attr("use_cudnn_on_gpu"), "padding",
              _op.get_attr("padding"), "data_format",
              _op.get_attr("data_format"))
  else:
    _attr_T, _inputs_T = _execute.args_to_matching_eager([input, filter], _ctx)
    (input, filter) = _inputs_T
    _attr_T = _attr_T.as_datatype_enum
    _inputs_flat = [input, filter]
    _attrs = ("T", _attr_T, "strides", strides, "use_cudnn_on_gpu",
              use_cudnn_on_gpu, "padding", padding, "data_format",
              data_format)
    _result = _execute.execute(b"Conv2D", 1, inputs=_inputs_flat,
                               attrs=_attrs, ctx=_ctx, name=name)
  _execute.record_gradient(
      "Conv2D", _inputs_flat, _attrs, _result, name)
  _result, = _result
  return _result

注意函數(shù)的幾個(gè)參數(shù)
每個(gè)參數(shù)的shape均不相同
最終返回Returns:
A Tensor. Has the same type as input.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市吉嫩,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌项栏,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件州丹,死亡現(xiàn)場離奇詭異下翎,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)欺抗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來强重,“玉大人绞呈,你說我怎么就攤上這事〖渚埃” “怎么了佃声?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長倘要。 經(jīng)常有香客問我圾亏,道長,這世上最難降的妖魔是什么封拧? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任志鹃,我火速辦了婚禮,結(jié)果婚禮上泽西,老公的妹妹穿的比我還像新娘弄跌。我一直安慰自己,他們只是感情好尝苇,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著埠胖,像睡著了一般糠溜。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上直撤,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天非竿,我揣著相機(jī)與錄音,去河邊找鬼谋竖。 笑死红柱,一個(gè)胖子當(dāng)著我的面吹牛承匣,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播锤悄,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼韧骗,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了零聚?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤隶症,失蹤者是張志新(化名)和其女友劉穎政模,沒想到半個(gè)月后蚂会,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體淋样,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡胁住,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年趁猴,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片措嵌。...
    茶點(diǎn)故事閱讀 40,133評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡躲叼,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出企巢,到底是詐尸還是另有隱情枫慷,我是刑警寧澤浪规,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布或听,位于F島的核電站笋婿,受9級特大地震影響誉裆,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜缸濒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一足丢、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧庇配,春花似錦斩跌、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽啸澡。三九已至袖订,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間洛姑,已是汗流浹背上沐。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工吏口, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留奄容,地道東北人产徊。 一個(gè)月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓昂勒,卻偏偏與公主長得像舟铜,于是被迫代替她去往敵國和親戈盈。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容