extorch.nn.modules.operation

Identity

BNReLU

A batch-normalization layer followed by relu.

ReLUBN

A batch-normalization layer following relu.

ConvBNReLU

A convolution followed by batch-normalization and ReLU.

ReLUConvBN

A ReLU followed by convolution and batch-normalization.

class extorch.nn.modules.operation.BNReLU(in_channels: int, affine: bool = True)[source]

Bases: torch.nn.modules.module.Module

A batch-normalization layer followed by relu.

Parameters
  • in_channels (int) – Number of channels in the input image.

  • affine – A boolean value that when set to True, this module has learnable affine parameters. Default: True.

Examples::
>>> m = BNReLU(32, True)
>>> input = torch.randn(2, 32, 10, 3)
>>> output = m(input)
forward(input: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class extorch.nn.modules.operation.ConvBN(in_channels: int, out_channels: int, kernel_size: Union[int, Tuple[int, int]], stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, groups: int = 1, bias: bool = True, affine: bool = True, **kwargs)[source]

Bases: torch.nn.modules.module.Module

A convolution followed by batch-normalization.

Parameters
  • in_channels (int) – Number of channels in the input image.

  • out_channels (int) – Number of channels produced by the convolution.

  • kernel_size (int or tuple) – Size of the convolving kernel.

  • stride (int or tuple, optional) – Stride of the convolution. Default: 1.

  • padding (int, tuple or str, optional) – Padding added to all four sides of e input. Default: 0.

  • dilation (int or tuple, optional) – Spacing between kernel elements. Default: 1.

  • groups (int, optional) – Number of blocked connections from input channels to output channels. Default: 1.

  • bias (bool, optional) – If True, adds a learnable bias to the output. Default: True.

  • affine (bool) – A boolean value that when set to True, the batch-normalization layer has learnable affine parameters. Default: True.

  • kwargs – Other configurations of the convolution.

Examples::
>>> m = ConvBN(3, 10, 3, 1)
>>> input = torch.randn(2, 3, 32, 32)
>>> output = m(input)
forward(input: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class extorch.nn.modules.operation.ConvBNReLU(in_channels: int, out_channels: int, kernel_size: Union[int, Tuple[int, int]], stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, groups: int = 1, bias: bool = True, affine: bool = True, **kwargs)[source]

Bases: torch.nn.modules.module.Module

A convolution followed by batch-normalization and ReLU.

Parameters
  • in_channels (int) – Number of channels in the input image.

  • out_channels (int) – Number of channels produced by the convolution.

  • kernel_size (int or tuple) – Size of the convolving kernel.

  • stride (int or tuple, optional) – Stride of the convolution. Default: 1.

  • padding (int, tuple or str, optional) – Padding added to all four sides of e input. Default: 0.

  • dilation (int or tuple, optional) – Spacing between kernel elements. Default: 1.

  • groups (int, optional) – Number of blocked connections from input channels to output channels. Default: 1.

  • bias (bool, optional) – If True, adds a learnable bias to the output. Default: True.

  • affine (bool) – A boolean value that when set to True, the batch-normalization layer has learnable affine parameters. Default: True.

  • kwargs – Other configurations of the convolution.

Examples::
>>> m = ConvBNReLU(3, 10, 3, 1)
>>> input = torch.randn(2, 3, 32, 32)
>>> output = m(input)
forward(input: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class extorch.nn.modules.operation.ConvReLU(in_channels: int, out_channels: int, kernel_size: Union[int, Tuple[int, int]], stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, groups: Optional[int] = 1, bias: Optional[bool] = True, inplace: Optional[bool] = False, **kwargs)[source]

Bases: torch.nn.modules.module.Module

A convolution followed by a ReLU.

Parameters
  • in_channels (int) – Number of channels in the input image.

  • out_channels (int) – Number of channels produced by the convolution.

  • kernel_size (int or tuple) – Size of the convolving kernel.

  • stride (int or tuple, optional) – Stride of the convolution. Default: 1.

  • padding (int, tuple or str, optional) – Padding added to all four sides of e input. Default: 0.

  • dilation (int or tuple, optional) – Spacing between kernel elements. Default: 1.

  • groups (Optional[int]) – Number of blocked connections from input channels to output channels. Default: 1.

  • bias (Optional[bool]) – If True, adds a learnable bias to the output. Default: True.

  • inplace (Optional[bool]) – ReLU can optionally do the operation in-place. Default: False.

  • kwargs – Other configurations of the convolution.

Examples::
>>> m = ConvReLU(3, 10, 3, 1)
>>> input = torch.randn(2, 3, 32, 32)
>>> output = m(input)
forward(input: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class extorch.nn.modules.operation.Identity[source]

Bases: torch.nn.modules.module.Module

forward(input: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class extorch.nn.modules.operation.ReLUBN(in_channels: int, affine: bool = True)[source]

Bases: torch.nn.modules.module.Module

A batch-normalization layer following relu.

Parameters
  • in_channels (int) – Number of channels in the input image.

  • affine – A boolean value that when set to True, this module has learnable affine parameters. Default: True.

Examples::
>>> m = ReLUBN(32, True)
>>> input = torch.randn(2, 32, 10, 3)
>>> output = m(input)
forward(input: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class extorch.nn.modules.operation.ReLUConvBN(in_channels: int, out_channels: int, kernel_size: Union[int, Tuple[int, int]], stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, groups: int = 1, bias: bool = True, affine: bool = True, **kwargs)[source]

Bases: torch.nn.modules.module.Module

A ReLU followed by convolution and batch-normalization.

Parameters
  • in_channels (int) – Number of channels in the input image.

  • out_channels (int) – Number of channels produced by the convolution.

  • kernel_size (int or tuple) – Size of the convolving kernel.

  • stride (int or tuple, optional) – Stride of the convolution. Default: 1.

  • padding (int, tuple or str, optional) – Padding added to all four sides of e input. Default: 0.

  • dilation (int or tuple, optional) – Spacing between kernel elements. Default: 1.

  • groups (int, optional) – Number of blocked connections from input channels to output channels. Default: 1.

  • bias (bool, optional) – If True, adds a learnable bias to the output. Default: True.

  • affine (bool) – A boolean value that when set to True, the batch-normalization layer has learnable affine parameters. Default: True.

  • kwargs – Other configurations of the convolution.

Examples::
>>> m = ReLUConvBN(3, 10, 3, 1)
>>> input = torch.randn(2, 3, 32, 32)
>>> output = m(input)
forward(input: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool