ggml_conv_2d_layer: Create a Reusable Conv2D Layer Object

View source: R/nn_functional.R

ggml_conv_2d_layerR Documentation

Create a Reusable Conv2D Layer Object

Description

Builds a layer object to be applied with ggml_apply, which is how a single set of convolution weights is shared between several inputs. This is the convolution counterpart of ggml_dense.

Usage

ggml_conv_2d_layer(
  filters,
  kernel_size,
  activation = NULL,
  strides = c(1L, 1L),
  padding = "valid",
  name = NULL,
  trainable = TRUE
)

Arguments

filters

Number of output filters.

kernel_size

Integer or length-2 integer vector.

activation

Activation function name or NULL.

strides

Integer or length-2 integer vector (default 1).

padding

"valid" or "same".

name

Optional character name.

trainable

Logical.

Details

For the ordinary pipe-style form that appends a conv layer to a graph (x |> ggml_layer_conv_2d(...)), see ggml_layer_conv_2d.

Value

A ggml_layer object.

See Also

ggml_apply, ggml_dense

Examples


# One convolution shared between two inputs.
shared <- ggml_conv_2d_layer(filters = 4L, kernel_size = 3L, activation = "relu")
x1 <- ggml_input(shape = c(8L, 8L, 1L))
x2 <- ggml_input(shape = c(8L, 8L, 1L))
o1 <- ggml_apply(x1, shared)
o2 <- ggml_apply(x2, shared)
stopifnot(identical(o1$layer_id, o2$layer_id))   # same weights


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.