DdpgCnnActor¶
- class torchrl.modules.DdpgCnnActor(action_dim: int, conv_net_kwargs: dict | None = None, mlp_net_kwargs: dict | None = None, use_avg_pooling: bool = False, device: DEVICE_TYPING | None = None)[源代码]¶
DDPG 卷积演员类。
在“使用深度强化学习进行连续控制”中提出,https://arxiv.org/pdf/1509.02971.pdf
DDPG 卷积演员将观察结果(观察到的像素的简单转换)作为输入,并从中返回动作向量,以及可用于价值估计的观察嵌入。它应该经过训练以最大化 DDPG Q 值网络返回的价值。
- 参数::
action_dim (int) – 动作向量的长度。
conv_net_kwargs (dict 或 dicts 列表, 可选) –
ConvNet 的关键字参数。默认为
>>> { ... 'in_features': None, ... "num_cells": [32, 64, 64], ... "kernel_sizes": [8, 4, 3], ... "strides": [4, 2, 1], ... "paddings": [0, 0, 1], ... 'activation_class': torch.nn.ELU, ... 'norm_class': None, ... 'aggregator_class': SquashDims, ... 'aggregator_kwargs': {"ndims_in": 3}, ... 'squeeze_output': True, ... } #
mlp_net_kwargs –
MLP 的关键字参数。默认为
>>> { ... 'in_features': None, ... 'out_features': action_dim, ... 'depth': 2, ... 'num_cells': 200, ... 'activation_class': nn.ELU, ... 'bias_last_layer': True, ... }
use_avg_pooling (bool, 可选) – 如果
True
,则使用AvgPooling
层来聚合输出。默认为False
。device (torch.device, 可选) – 用于创建模块的设备。
示例
>>> import torch >>> from torchrl.modules import DdpgCnnActor >>> actor = DdpgCnnActor(action_dim=4) >>> print(actor) DdpgCnnActor( (convnet): ConvNet( (0): LazyConv2d(0, 32, kernel_size=(8, 8), stride=(4, 4)) (1): ELU(alpha=1.0) (2): Conv2d(32, 64, kernel_size=(4, 4), stride=(2, 2)) (3): ELU(alpha=1.0) (4): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ELU(alpha=1.0) (6): SquashDims() ) (mlp): MLP( (0): LazyLinear(in_features=0, out_features=200, bias=True) (1): ELU(alpha=1.0) (2): Linear(in_features=200, out_features=200, bias=True) (3): ELU(alpha=1.0) (4): Linear(in_features=200, out_features=4, bias=True) ) ) >>> obs = torch.randn(10, 3, 64, 64) >>> action, hidden = actor(obs) >>> print(action.shape) torch.Size([10, 4]) >>> print(hidden.shape) torch.Size([10, 2304])