Class GroupNorm

Base class for implementing a module, which is a reusable portion of a neural network. Modules can contain other modules, allowing for a tree-like structure.

To add a submodule to a module, assign it as a property of the module in the constructor. Its name will be the name of the property.

Modules can also contain Parameter objects, which are tensors that are automatically updated by optimizers and are saved when calling saveDict(). To add a parameter to a module, assign it as a property of the module in the constructor.

Module subtypes implement a forward function in order to define the computation of the module.

class Model extends torch.nn.Module {
conv1: torch.nn.Conv2d;
conv2: torch.nn.Conv2d;
constructor() {
super();
this.conv1 = torch.nn.Conv2d(1, 20, 5);
this.conv2 = torch.nn.Conv2d(20, 20, 5);
}
forward(input: torch.Tensor): torch.Tensor {
let output = this.conv1.forward(input);
output = output.relu();
output = this.conv2.forward(output);
output = output.relu();
return output;
}
}

Hierarchy

Constructors

Properties

numChannels: number
numGroups: number

Accessors

  • get [toStringTag](): string
  • Returns string

  • get children(): Module[]
  • Returns the immediate children (submodules) of this module.

    Returns Module[]

  • get namedChildren(): [string | number, Module][]
  • Returns the immediate children (submodules) of this module along with their names.

    Returns [string | number, Module][]

  • get training(): boolean
  • Returns boolean

Methods

  • Adds a child module of the current module.

    The module can be accessed as a property using the given name.

    Parameters

    • name: string | number

      name of the child module

    • module: Module

      child module to be added

    Returns void

  • Loads the state of the module and its descendants from the given state dictionary.

    Parameters

    • stateDict: StateDict

      The state dictionary containing the state of the module to load.

    Returns void

  • Parameters

    • prefix: string = ""
    • recurse: boolean = true
    • removeDuplicate: boolean = true

    Returns Generator<[string, null | Tensor], any, unknown>

  • Returns this module and its descendants' along with their prefixed names.

    Parameters

    • Optional memo: Set<Module>

      is a set of modules used to avoid double counting.

    • prefix: string = ""

      is prependended to the names of the modules.

    • removeDuplicate: boolean = true

      is a boolean indicating whether to remove duplicate modules.

    Returns Generator<[string | number, Module], any, unknown>

    a generator of [prefixed name, module] pairs.

  • Gets this module and its descendants' (if recurse = true) parameters along with their prefixed names.

    Parameters

    • prefix: string = ""

      is prependended to the names of the parameters

    • recurse: boolean = true

      whether to include submodule parameters

    • removeDuplicate: boolean = true

      whether to remove duplicate parameters

    Returns Generator<[string, Parameter], any, unknown>

    a generator of [prefixed name, parameter] pairs

  • Change if autograd should record operations on parameters in this module.

    Parameters

    • requiresGrad: boolean = true

      whether to enable gradient calculation for parameters in this module.

    Returns ThisType<Module>

    this module

  • Returns the state dictionary of the module and its descendants.

    Parameters

    • Optional destination: StateDict

      An optional state dictionary to update with the module's state.

    • prefix: string = ""

      A string to prepend to the names of the state entries (default is an empty string).

    • keepVars: boolean = true

      A boolean flag, if true keeps the tensors attached to autograd (default is true).

    Returns StateDict

    The updated state dictionary containing the module's state.

  • Produces a multiline readable string of the module and its descendants.

    Returns string

    A string representation of the module and its descendants.

  • Sets the module in training mode.

    Parameters

    • mode: boolean = true

      whether to set training mode (true) or evaluation mode (false).

    Returns ThisType<Module>

    this module

  • Zeros out the gradients of all parameters. That can be accomplished either by setting the grad property to null (setToNull=true) or by filling the gradient tensor with zeros (setToNull=false).

    Parameters

    • setToNull: boolean = true

      whether to set gradients to null (true) or to zero tensors (false).

    Returns ThisType<Module>

    this module

Generated using TypeDoc