Conv2d
Source:R/gen-namespace-docs.R, R/gen-namespace-examples.R, R/gen-namespace.R
torch_conv2d.RdConv2d
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,.,.) =
#> -7.0066 4.4925 -16.1039 2.9467 -0.7041
#> -6.3461 7.5743 -9.2212 2.8496 -6.2783
#> 3.0018 3.6653 3.9287 4.3608 -7.3198
#> 3.2666 -9.4097 4.4943 8.0171 -19.7106
#> 0.7662 -0.9384 5.2524 -5.5255 -0.0248
#>
#> (1,2,.,.) =
#> 3.8501 9.1569 -3.4568 -0.9357 1.2627
#> -3.3323 -5.6714 -1.2168 2.8138 -2.9487
#> 0.6927 -0.4000 3.0222 0.9015 -1.8428
#> 0.0012 0.4966 -10.8579 11.9719 -6.3325
#> 1.4279 2.8926 2.3333 -3.6666 -9.0881
#>
#> (1,3,.,.) =
#> -7.8250 0.4249 0.3988 9.8024 -2.2569
#> 3.0475 1.0591 -10.3694 7.2950 -2.7880
#> 3.6239 -1.0246 3.6069 -9.1539 0.3733
#> -6.0142 10.7805 2.9294 -5.2215 9.2369
#> -0.2793 -3.6346 2.5180 -0.2760 -5.6622
#>
#> (1,4,.,.) =
#> 4.3047 3.5312 6.4958 1.4355 5.4987
#> 4.5059 1.0209 6.0836 2.1999 2.1736
#> -4.5698 -11.7424 2.0312 -4.8006 4.7962
#> 1.3183 -2.5849 -4.9302 6.5903 -0.8207
#> -0.7663 0.6811 -0.4265 1.9395 0.7642
#>
#> (1,5,.,.) =
#> 2.6178 -3.2662 0.1016 -5.3442 -0.8028
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{1,8,5,5} ]