日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

pytorch中的torch.nn.Conv2d()函數(shù)圖文詳解_python

作者:夏普通 ? 更新時(shí)間: 2022-05-01 編程語言

一、官方文檔介紹

官網(wǎng)

nn.Conv2d:對(duì)由多個(gè)輸入平面組成的輸入信號(hào)進(jìn)行二維卷積

二、torch.nn.Conv2d()函數(shù)詳解

參數(shù)詳解

torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)

參數(shù) 參數(shù)類型 ? ?
in_channels int Number of channels in the input image 輸入圖像通道數(shù)
out_channels int Number of channels produced by the convolution 卷積產(chǎn)生的通道數(shù)
kernel_size (int or tuple) Size of the convolving kernel 卷積核尺寸,可以設(shè)為1個(gè)int型數(shù)或者一個(gè)(int, int)型的元組。例如(2,3)是高2寬3卷積核
stride (int or tuple, optional) Stride of the convolution. Default: 1 卷積步長,默認(rèn)為1。可以設(shè)為1個(gè)int型數(shù)或者一個(gè)(int, int)型的元組。
padding (int or tuple, optional) Zero-padding added to both sides of the input. Default: 0 填充操作,控制padding_mode的數(shù)目。
padding_mode (string, optional) ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’ padding模式,默認(rèn)為Zero-padding 。
dilation (int or tuple, optional) Spacing between kernel elements. Default: 1 擴(kuò)張操作:控制kernel點(diǎn)(卷積核點(diǎn))的間距,默認(rèn)值:1。
groups (int, optional) Number of blocked connections from input channels to output channels. Default: 1 group參數(shù)的作用是控制分組卷積,默認(rèn)不分組,為1組。
bias (bool, optional) If True, adds a learnable bias to the output. Default: True 為真,則在輸出中添加一個(gè)可學(xué)習(xí)的偏差。默認(rèn):True。

參數(shù)dilation——擴(kuò)張卷積(也叫空洞卷積)

dilation操作動(dòng)圖演示如下:

Dilated Convolution with a 3 x 3 kernel and dilation rate 2

擴(kuò)張卷積核為3×3,擴(kuò)張率為2

參數(shù)groups——分組卷積

Group Convolution顧名思義,則是對(duì)輸入feature map進(jìn)行分組,然后每組分別卷積。

三、代碼實(shí)例

import torch

x = torch.randn(3,1,5,4)
print(x)

conv = torch.nn.Conv2d(1,4,(2,3))
res = conv(x)

print(res.shape)    # torch.Size([3, 4, 4, 2])

輸入:x[ batch_size, channels, height_1, width_1 ]

  • batch_size,一個(gè)batch中樣本的個(gè)數(shù) 3
  • channels,通道數(shù),也就是當(dāng)前層的深度 1
  • height_1, 圖片的高 5
  • width_1, 圖片的寬 4

卷積操作:Conv2d[ channels, output, height_2, width_2 ]

  • channels,通道數(shù),和上面保持一致,也就是當(dāng)前層的深度 1
  • output ,輸出的深度 4【需要4個(gè)filter】
  • height_2,卷積核的高 2
  • width_2,卷積核的寬 3

輸出:res[ batch_size,output, height_3, width_3 ]

  • batch_size,,一個(gè)batch中樣例的個(gè)數(shù),同上 3
  • output, 輸出的深度 4
  • height_3, 卷積結(jié)果的高度 4
  • width_3,卷積結(jié)果的寬度 2

一個(gè)樣本卷積示例:

總結(jié)?

原文鏈接:https://blog.csdn.net/qq_34243930/article/details/107231539

欄目分類
最近更新