Learn R Programming

torch (version 0.1.0)

nn_module: Base class for all neural network modules.

Description

Your models should also subclass this class.

Usage

nn_module(
  classname = NULL,
  inherit = nn_Module,
  ...,
  parent_env = parent.frame()
)

Arguments

classname

an optional name for the module

inherit

an optional module to inherit from

...

methods implementation

parent_env

passed to R6::R6Class().

Details

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes.

Examples

Run this code
# NOT RUN {
if (torch_is_installed()) {
model <- nn_module(
 initialize = function() {
   self$conv1 <- nn_conv2d(1, 20, 5)
   self$conv2 <- nn_conv2d(20, 20, 5)
 },
 forward = function(input) {
   input <- self$conv1(input)
   input <- nnf_relu(input)
   input <- self$conv2(input)
   input <- nnf_relu(input)
   input
 }
)

}
# }

Run the code above in your browser using DataLab