以下是一些我在使用pytorch中遇到的一些類及函式,為了便於理解和使用,將官網中的說明摘錄一些下來。
**
class conv1d(_convnd):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1,
bias=true, padding_mode='zeros'):
kernel_size = _single(kernel_size)
stride = _single(stride)
padding = _single(padding)
dilation = _single(dilation)
super(conv1d, self).__init__(
in_channels, out_channels, kernel_size, stride, padding, dilation,
false, _single(0), groups, bias, padding_mode)
類的說明:對由多個輸入平面組成的輸入訊號應用一維卷積
官網中對初始化函式中一些引數的說明:
in_channels (int): number of channels in the input image機翻out_channels (int): number of channels produced by the convolution
kernel_size (int or tuple): size of the convolving kernel
stride (int or tuple, optional): stride of the convolution. default: 1
padding (int or tuple, optional): zero-padding added to both sides of the input. default: 0
dilation (int or tuple, optional): spacing between kernel elements. default: 1
groups (int, optional): number of blocked connections from input channels to output channels. default: 1
bias (bool, optional): if
true
, adds a learnable bias to the output. default:true
padding_mode (string, optional). accepted values
zeros
andcircular
default:zeros
in_channels (int): 輸入影象中的通道數**out_channels (int): 由卷積產生的通道數
kernel_size (int or tuple): 卷積核的大小
stride (int or tuple, optional): 卷積的步幅
padding (int or tuple, optional): 輸入的兩邊都加上了零填充
dilation (int or tuple, optional): 卷積核元素之間的間距
groups (int, optional): 從輸入通道到輸出通道的阻塞連線數
bias (bool, optional): 如果為「 true」 ,則在輸出中新增可學習的偏差
padding_mode (string, optional): 接受值「0」和「迴圈」
class conv2d(_convnd):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1,
bias=true, padding_mode='zeros'):
kernel_size = _pair(kernel_size)
stride = _pair(stride)
padding = _pair(padding)
dilation = _pair(dilation)
super(conv2d, self).__init__(
in_channels, out_channels, kernel_size, stride, padding, dilation,
false, _pair(0), groups, bias, padding_mode)
類的說明:在由多個輸入平面組成的輸入訊號上應用二維卷積。
官網中對初始化函式中一些引數的說明:
in_channels (int): number of channels in the input image機翻out_channels (int): number of channels produced by the convolution
kernel_size (int or tuple): size of the convolving kernel
stride (int or tuple, optional): stride of the convolution. default: 1
padding (int or tuple, optional): zero-padding added to both sides of the input. default: 0
dilation (int or tuple, optional): spacing between kernel elements. default: 1
groups (int, optional): number of blocked connections from input channels to output channels. default: 1
bias (bool, optional): if
true
, adds a learnable bias to the output. default:true
padding_mode (string, optional). accepted values
zeros
andcircular
default:zeros
in_channels (int): 輸入影象中的通道數以下是部落格中對引數的含義做的進一步解釋。out_channels (int): 由卷積產生的通道數
kernel_size (int or tuple): 卷積核的大小
stride (int or tuple, optional): 卷積的步幅
padding (int or tuple, optional): 輸入的兩邊都加上了零填充
dilation (int or tuple, optional): 卷積核元素之間的間距
groups (int, optional): 從輸入通道到輸出通道的阻塞連線數
bias (bool, optional): 如果為「 true」 ,則在輸出中新增可學習的偏差
padding_mode (string, optional): 接受值「0」和「迴圈」
下面是官網對於nn.conv2d
輸入輸出shape的說明。
以及官網中給出的樣例
>>> # with square kernels and equal stridepytorch官網>>> m = nn.conv2d(16, 33, 3, stride=2)
>>> # non-square kernels and unequal stride and with padding
>>> m = nn.conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2))
>>> # non-square kernels and unequal stride and with padding and dilation
>>> m = nn.conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1))
>>> input = torch.randn(20, 16, 50, 100)
>>> output = m(input)
pytorch學習筆記(9)——nn.conv2d和其中的padding策略
pytorch的gather函式的一些粗略的理解
先給出官方文件的解釋,我覺得官方的文件寫的已經很清楚了,四個引數分別是input,dim,index,out,輸出的tensor是以index為大小的tensor。其中,這就是最關鍵的定義 out i j k tensor index i j k j k dim 0 out i j k tensor...
PyTorch的一些線性代數函式
pytorch還支援一些線性函式,免得用起來的時候自己造輪子,具體用法參考官方文件。如下表所示 函式功能 trace 對 角線元素之和 矩陣的跡 diag 對 角線元素 triu tril 矩陣的上三 角 下三 角,可指定偏移量 mm bmm 矩陣乘法,batch的矩陣乘法 addmm addbmm...
pytorch裡一些函式的說明記錄
thlongstorage thtensor newsizeof thtensor self thlongstorage thtensor newstrideof thtensor self 把thtensor的size stride資料提取出來,賦值給乙個新的thlongstorage並返回 th...