Skip to contents

Conv2d

Usage

torch_conv2d(
  input,
  weight,
  bias = list(),
  stride = 1L,
  padding = 0L,
  dilation = 1L,
  groups = 1L
)

Arguments

input

input tensor of shape \((\mbox{minibatch} , \mbox{in\_channels} , iH , iW)\)

weight

filters of shape \((\mbox{out\_channels} , \frac{\mbox{in\_channels}}{\mbox{groups}} , kH , kW)\)

bias

optional bias tensor of shape \((\mbox{out\_channels})\). Default: NULL

stride

the stride of the convolving kernel. Can be a single number or a tuple (sH, sW). Default: 1

padding

implicit paddings on both sides of the input. Can be a single number or a tuple (padH, padW). Default: 0

dilation

the spacing between kernel elements. Can be a single number or a tuple (dH, dW). Default: 1

groups

split input into groups, \(\mbox{in\_channels}\) should be divisible by the number of groups. Default: 1

conv2d(input, weight, bias=NULL, stride=1, padding=0, dilation=1, groups=1) -> Tensor

Applies a 2D convolution over an input image composed of several input planes.

See nn_conv2d() for details and output shape.

Examples

if (torch_is_installed()) {

# With square kernels and equal stride
filters = torch_randn(c(8,4,3,3))
inputs = torch_randn(c(1,4,5,5))
nnf_conv2d(inputs, filters, padding=1)
}
#> torch_tensor
#> (1,1,.,.) = 
#>  -0.4205  5.5326  3.8507  5.9316 -1.3754
#>   3.7027 -5.0168  0.7241 -3.4465 -3.9617
#>   4.1951 -6.9591 -0.3911 -5.7254  4.2514
#>  -3.8776  2.2262 -5.9519  4.7296 -4.3130
#>  -5.7552 -7.1466 -7.8715  1.9848  4.5258
#> 
#> (1,2,.,.) = 
#>    3.4771  -3.7985  -1.1954   5.9207  -4.4058
#>    4.9761  -3.9643  11.7336  -6.9049  -1.3944
#>   -4.2270   2.3480  -5.2240   2.8035   0.6967
#>   -3.0381  -3.5416  -2.9951  -3.9102  -0.1140
#>    3.3137  -4.7079   3.2192  -2.1023  -1.2522
#> 
#> (1,3,.,.) = 
#>   2.2731 -7.3002  0.9491 -1.7577  1.5221
#>  -2.6324  3.1366  0.4026  4.4875  1.1830
#>  -1.1941 -0.6082  0.0801 -11.7328 -2.6824
#>   0.7493  6.7134  1.0917  1.8614 -5.0644
#>  -1.1974 -6.8208 -3.4701  4.2588  0.3884
#> 
#> (1,4,.,.) = 
#>    5.6375  -5.1921   2.6715   1.2529 -10.1577
#>   -4.9732  -1.8251   5.2585   1.1183   5.9632
#>   -6.7279   7.2313  -7.7422  -7.8702  10.8867
#>   -1.7638   3.4449   1.4203   1.8338  -2.4842
#>   -3.7392   1.9245  -0.2677   4.3679  -1.0309
#> 
#> (1,5,.,.) = 
#>   3.7402  2.6718  1.5691 -2.9978  4.4694
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{1,8,5,5} ]