Conv3dNet¶
- class torchrl.modules.Conv3dNet(in_features: int | None = None, depth: int | None = None, num_cells: collections.abc.Sequence[int] | int = None, kernel_sizes: collections.abc.Sequence[int] | int = 3, strides: collections.abc.Sequence[int] | int = 1, paddings: collections.abc.Sequence[int] | int = 0, activation_class: type[torch.nn.modules.module.Module] | collections.abc.Callable = <class 'torch.nn.modules.activation.ELU'>, activation_kwargs: dict | list[dict] | None = None, norm_class: type[torch.nn.modules.module.Module] | collections.abc.Callable | None = None, norm_kwargs: dict | list[dict] | None = None, bias_last_layer: bool = True, aggregator_class: type[torch.nn.modules.module.Module] | collections.abc.Callable | None = <class 'torchrl.modules.models.utils.SquashDims'>, aggregator_kwargs: dict | None = None, squeeze_output: bool = False, device: ~typing.Optional[~typing.Union[~torch.device, str, int]] = None)[source]¶
A 3D-convolutional neural network.
- Parameters:
in_features (int, optional) – number of input features. A lazy implementation that automatically retrieves the input size will be used if none is provided.
depth (int, optional) – depth of the network. A depth of
1will produce a single linear layer network with the desired input size, and with an output size equal to the last element of thenum_cellsargument. If nodepthis indicated, thedepthinformation should be contained in thenum_cellsargument (see below). Ifnum_cellsis an iterable anddepthis indicated, both should match:len(num_cells)must be equal to thedepth.num_cells (int or sequence of int, optional) – number of cells of every layer in between the input and output. If an integer is provided, every layer will have the same number of cells and the depth will be retrieved from
depth. If an iterable is provided, the linear layersout_featureswill match the content of num_cells. Defaults to[32, 32, 32]or[32] * depth` is depth is not ``None.kernel_sizes (int, sequence of int, optional) – Kernel size(s) of the conv network. If iterable, the length must match the depth, defined by the
num_cellsor depth arguments. Defaults to3.strides (int or sequence of int) – Stride(s) of the conv network. If iterable, the length must match the depth, defined by the
num_cellsor depth arguments. Defaults to1.activation_class (Type[nn.Module] or callable) – activation class or constructor to be used. Defaults to
Tanh.activation_kwargs (dict or list of dicts, optional) – kwargs to be used with the activation class. A list of kwargs of length
depthwith one element per layer can also be provided.norm_class (Type or callable, optional) – normalization class, if any.
norm_kwargs (dict or list of dicts, optional) – kwargs to be used with the normalization layers. A list of kwargs of length
depthwith one element per layer can also be provided.bias_last_layer (bool) – if
True, the last Linear layer will have a bias parameter. Defaults toTrue.aggregator_class (Type[nn.Module] or callable) – aggregator class or constructor to use at the end of the chain. Defaults to
SquashDims.aggregator_kwargs (dict, optional) – kwargs for the
aggregator_classconstructor.squeeze_output (bool) – whether the output should be squeezed of its singleton dimensions. Defaults to
False.device (torch.device, optional) – device to create the module on.
Examples
>>> # All of the following examples provide valid, working MLPs >>> cnet = Conv3dNet(in_features=3, depth=1, num_cells=[32,]) >>> print(cnet) Conv3dNet( (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (1): ELU(alpha=1.0) (2): SquashDims() ) >>> cnet = Conv3dNet(in_features=3, depth=4, num_cells=32) >>> print(cnet) Conv3dNet( (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (1): ELU(alpha=1.0) (2): Conv3d(32, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (3): ELU(alpha=1.0) (4): Conv3d(32, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (5): ELU(alpha=1.0) (6): Conv3d(32, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (7): ELU(alpha=1.0) (8): SquashDims() ) >>> cnet = Conv3dNet(in_features=3, num_cells=[32, 33, 34, 35]) # defines the depth by the num_cells arg >>> print(cnet) Conv3dNet( (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (1): ELU(alpha=1.0) (2): Conv3d(32, 33, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (3): ELU(alpha=1.0) (4): Conv3d(33, 34, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (5): ELU(alpha=1.0) (6): Conv3d(34, 35, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (7): ELU(alpha=1.0) (8): SquashDims() ) >>> cnet = Conv3dNet(in_features=3, num_cells=[32, 33, 34, 35], kernel_sizes=[3, 4, 5, (2, 3, 4)]) # defines kernels, possibly rectangular >>> print(cnet) Conv3dNet( (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1)) (1): ELU(alpha=1.0) (2): Conv3d(32, 33, kernel_size=(4, 4, 4), stride=(1, 1, 1)) (3): ELU(alpha=1.0) (4): Conv3d(33, 34, kernel_size=(5, 5, 5), stride=(1, 1, 1)) (5): ELU(alpha=1.0) (6): Conv3d(34, 35, kernel_size=(2, 3, 4), stride=(1, 1, 1)) (7): ELU(alpha=1.0) (8): SquashDims() )