ExcludeTransform¶
- class torchrl.envs.transforms.ExcludeTransform(*excluded_keys, inverse: bool = False)[源代码]¶
从数据中排除键。
- 参数:
*excluded_keys (NestedKey 的可迭代对象) – 要排除的键的名称。如果键不存在,则会简单地忽略。
inverse (bool, 可选) – 如果为
True
,则排除将在inv
调用期间发生。默认为False
。
示例
>>> import gymnasium >>> from torchrl.envs import GymWrapper >>> env = TransformedEnv( ... GymWrapper(gymnasium.make("Pendulum-v1")), ... ExcludeTransform("truncated") ... ) >>> env.rollout(3) TensorDict( fields={ action: Tensor(shape=torch.Size([3, 1]), device=cpu, dtype=torch.float32, is_shared=False), done: Tensor(shape=torch.Size([3, 1]), device=cpu, dtype=torch.bool, is_shared=False), next: TensorDict( fields={ done: Tensor(shape=torch.Size([3, 1]), device=cpu, dtype=torch.bool, is_shared=False), observation: Tensor(shape=torch.Size([3, 3]), device=cpu, dtype=torch.float32, is_shared=False), reward: Tensor(shape=torch.Size([3, 1]), device=cpu, dtype=torch.float32, is_shared=False)}, batch_size=torch.Size([3]), device=cpu, is_shared=False), observation: Tensor(shape=torch.Size([3, 3]), device=cpu, dtype=torch.float32, is_shared=False)}, batch_size=torch.Size([3]), device=cpu, is_shared=False)
- forward(tensordict: TensorDictBase) TensorDictBase ¶
读取输入张量字典,并对选定的键应用转换。
- transform_output_spec(output_spec: CompositeSpec) CompositeSpec [源代码]¶
转换输出规范,以便生成的规范与转换映射匹配。
此方法通常应保持不变。更改应使用
transform_observation_spec()
、transform_reward_spec()
和transformfull_done_spec()
实现。:param output_spec: 转换前的规范 :type output_spec: TensorSpec- 返回值:
转换后的预期规范