Torch-style 2D convolution in NCHW layout: x is
[batch, in_channels, height, width], weight is
[out_channels, in_channels / groups, kh, kw], output is
[batch, out_channels, out_h, out_w]. Symmetric zero padding.
Usage
nv_conv2d(
x,
weight,
stride = 1L,
padding = 0L,
dilation = 1L,
groups = 1L,
precision = "highest"
)Arguments
- x
(
arrayish)[N, C_in, H, W]. Can be any data type;xandweightare promoted to a common data type. An R value assumes the other operand's data type, and materializes at its default data type when that has none either.- weight
(
arrayish)[C_out, C_in / groups, kH, kW]. Promoted together withx– seex.- stride
(
integer())
Length 1 or 2.- padding
(
integer())
Symmetric padding, length 1 or 2.- dilation
(
integer())
Kernel dilation, length 1 or 2.- groups
(
integer(1))
Grouped/depthwise convolution.- precision
(
character(1))"highest","high"or"default".
Value
(arrayish)
Has the operands' common data type, and shape
[N, C_out, out_H, out_W].
Examples
# one batch, one channel, 4x4, convolved with a 3x3 kernel
x <- nv_array(1:16, shape = c(1, 1, 4, 4), dtype = "f32")
weight <- nv_fill(1, shape = c(1, 1, 3, 3), dtype = "f32")
nv_conv2d(x, weight)
#> AnvlArray
#> (1,1,.,.) =
#> 54 90
#> 63 99
#> [ CPUf32{1,1,2,2} ]
# two output channels give a result with two channels
weight2 <- nv_fill(1, shape = c(2, 1, 3, 3), dtype = "f32")
shape(nv_conv2d(x, weight2))
#> [1] 1 2 2 2