FrameSkipTransform¶
- class torchrl.envs.transforms.FrameSkipTransform(frame_skip: int = 1)[source]¶
一个帧跳过转换。
此转换在父环境中重复应用相同的动作,这在某些训练的 SOTA 实现中可以提高稳定性。
- 参数:
frame_skip (int, optional) – 一个正整数,表示必须应用相同动作的帧数。
- forward(tensordict)[source]¶
读取输入 tensordict,并对选定的键应用转换。
默认情况下,此方法
直接调用
_apply_transform()
。不调用
_step()
或_call()
。
此方法不在任何时候被 `env.step` 调用。但是,它在 `sample()` 中被调用。
注意
`forward` 还使用 `dispatch` 通过将参数名称转换为键来处理常规关键字参数。
示例
>>> class TransformThatMeasuresBytes(Transform): ... '''Measures the number of bytes in the tensordict, and writes it under `"bytes"`.''' ... def __init__(self): ... super().__init__(in_keys=[], out_keys=["bytes"]) ... ... def forward(self, tensordict: TensorDictBase) -> TensorDictBase: ... bytes_in_td = tensordict.bytes() ... tensordict["bytes"] = bytes ... return tensordict >>> t = TransformThatMeasuresBytes() >>> env = env.append_transform(t) # works within envs >>> t(TensorDict(a=0)) # Works offline too.