nn_module_dict: Container that allows named values

nn_module_dictR Documentation

Container that allows named values

Description

Container that allows named values

Usage

nn_module_dict(dict)

Arguments

dict

A named list of submodules that will be saved in that module.

See Also

nn_module_list()

Examples

if (torch_is_installed()) {
nn_module <- nn_module(
  initialize = function() {
    self$dict <- nn_module_dict(list(
      l1 = nn_linear(10, 20),
      l2 = nn_linear(20, 10)
    ))
  },
  forward = function(x) {
    x <- self$dict$l1(x)
    self$dict$l2(x)
  }
)
}

torch documentation built on June 7, 2023, 6:19 p.m.