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,.,.) = 
#>  -5.6926  3.6664 -6.1840 -1.1465  2.3333
#>  -3.5719 -1.0030 -6.6127 -5.5974 -3.0202
#>  -11.3880 -0.1526 -4.0290 -6.4884 -0.8734
#>  -0.4170 -10.5567  3.5576 -2.2289  0.5714
#>   2.2486 -4.2168 -0.8165 -7.9505  0.5207
#> 
#> (1,2,.,.) = 
#>   1.2942 -3.9079 -2.6725  7.3195 -4.1647
#>   1.2835  3.4129 -5.9809 -0.8689 -2.4085
#>   0.0943 -1.0464 -5.6167  4.9792 -6.2590
#>   1.0954  6.2196 -2.4399  0.8718 -1.0243
#>   5.4097 -4.4769 -4.2346 -1.4191  0.6925
#> 
#> (1,3,.,.) = 
#>    0.6000   1.0499   3.7814   3.5483   1.7238
#>   -4.7591   0.5203   0.3688  -6.7972  10.4535
#>   -5.2558  -0.1668  15.0585  -0.0842   5.0301
#>   -1.1866   0.7594  10.5002   0.4953   2.6495
#>    4.0079  -0.0336   8.2732   2.3334   0.8182
#> 
#> (1,4,.,.) = 
#>  -6.5214  3.3681 -5.2806 -5.8420  7.9082
#>  -6.9348  0.9661  5.3649 -8.7740  3.7408
#>  -7.6552  0.7153  4.9676 -2.7418  0.6383
#>   2.7019  0.0574  0.0613  3.3370 -0.0993
#>   2.8228 -2.0183  4.0642 -0.7295 -4.0679
#> 
#> (1,5,.,.) = 
#>   6.1298 -0.8779 -2.6865  5.7750 -1.8942
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{1,8,5,5} ]