快捷方式

Conv3dNet

class torchrl.modules.Conv3dNet(in_features: int | None = None, depth: int | None = None, num_cells: Sequence[int] | int = None, kernel_sizes: Sequence[int] | int = 3, strides: Sequence[int] | int = 1, paddings: Sequence[int] | int = 0, activation_class: Type[nn.Module] | Callable = <class 'torch.nn.modules.activation.ELU'>, activation_kwargs: dict | List[dict] | None = None, norm_class: Type[nn.Module] | Callable | None = None, norm_kwargs: dict | List[dict] | None = None, bias_last_layer: bool = True, aggregator_class: Type[nn.Module] | Callable | None = <class 'torchrl.modules.models.utils.SquashDims'>, aggregator_kwargs: dict | None = None, squeeze_output: bool = False, device: DEVICE_TYPING | None = None)[source]

一个 3D 卷积神经网络。

参数:
  • in_features (int, optional) – 输入特征的数量。如果未提供,将使用自动检索输入大小的惰性实现。

  • depth (int, optional) – 网络的深度。深度为 1 将生成一个具有所需输入大小和输出大小等于 num_cells 参数最后一个元素的单层线性网络。如果未指定 depth,则 depth 信息应包含在 num_cells 参数中(见下文)。如果 num_cells 是一个可迭代对象并且指定了 depth,则两者必须匹配:len(num_cells) 必须等于 depth

  • num_cells (intint 序列, optional) – 输入和输出之间每层的单元数量。如果提供一个整数,则每层将具有相同数量的单元,并且深度将从 depth 中获取。如果提供一个可迭代对象,则线性层的 out_features 将与 num_cells 的内容匹配。默认为 [32, 32, 32],如果 depth 不为 None,则默认为 [32] * depth

  • kernel_sizes (int, int 序列, optional) – 卷积网络的核大小。如果是可迭代对象,其长度必须与由 num_cells 或 depth 参数定义的深度匹配。默认为 3

  • strides (intint 序列) – 卷积网络的步长。如果是可迭代对象,其长度必须与由 num_cells 或 depth 参数定义的深度匹配。默认为 1

  • activation_class (Type[nn.Module] 或 callable) – 要使用的激活类或构造函数。默认为 ELU

  • activation_kwargs (dictdict 列表, optional) – 与激活类一起使用的关键字参数。也可以提供一个长度为 depth 的关键字参数列表,每层一个元素。

  • norm_class (Typecallable, optional) – 归一化类,如果存在。

  • norm_kwargs (dictdict 列表, optional) – 与归一化层一起使用的关键字参数。也可以提供一个长度为 depth 的关键字参数列表,每层一个元素。

  • bias_last_layer (bool) – 如果为 True,则最后一个线性层将具有一个偏置参数。默认为 True

  • aggregator_class (Type[nn.Module] 或 callable) – 在链末端使用的聚合器类或构造函数。默认为 SquashDims

  • aggregator_kwargs (dict, optional) – aggregator_class 构造函数的关键字参数。

  • squeeze_output (bool) – 输出是否应压缩其单例维度。默认为 False

  • device (torch.device, optional) – 创建模块所在的设备。

示例

>>> # 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()
)
forward(inputs: Tensor) Tensor[source]

定义每次调用时执行的计算。

应由所有子类重写。

注意

尽管前向传播的实现需要在该函数内定义,但之后应调用 Module 实例而非此函数本身,因为前者负责运行注册的钩子,而后者会默默忽略它们。

文档

查阅 PyTorch 的完整开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并解答您的疑问

查看资源