gym.wrappers.Monitor报错,无法使用
使用gym中的录制功能,报错,具体:
>>> import gym
>>> gym.wrappers.Monitor
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'gym.wrappers' has no attribute 'Monitor'
经过网上查询知道在gym的0.21以上版本API进行了更改,gym.wrappers.Monitor由
gym.wrappers.RecordVideo 和 gym.wrappers.RecordEpisodeStatistics 所替代:
注意,使用之前需要安装依赖:
pip install moviepy
import gym env = gym.make("BipedalWalker-v3",render_mode = 'human') env = gym.wrappers.RecordEpisodeStatistics(env) env = gym.wrappers.RecordVideo(env, f"videos/{gym.__version__}")
===================================================
关于gym.wrappers.RecordEpisodeStatistics的帮助文档:
class RecordEpisodeStatistics(gym.core.Wrapper)
| RecordEpisodeStatistics(*args, **kwds)
|
| This wrapper will keep track of cumulative rewards and episode lengths.
|
| At the end of an episode, the statistics of the episode will be added to ``info``
| using the key ``episode``. If using a vectorized environment also the key
| ``_episode`` is used which indicates whether the env at the respective index has
| the episode statistics.
|
| After the completion of an episode, ``info`` will look like this::
|
| >>> info = {
| ... ...
| ... "episode": {
| ... "r": "<cumulative reward>",
| ... "l": "<episode length>",
| ... "t": "<elapsed time since instantiation of wrapper>"
| ... },
| ... }
|
| For a vectorized environments the output will be in the form of::
|
| >>> infos = {
| ... ...
| ... "episode": {
| ... "r": "<array of cumulative reward>",
| ... "l": "<array of episode length>",
| ... "t": "<array of elapsed time since instantiation of wrapper>"
| ... },
| ... "_episode": "<boolean array of length num-envs>"
| ... }
|
| Moreover, the most recent rewards and episode lengths are stored in buffers that can be accessed via
| :attr:`wrapped_env.return_queue` and :attr:`wrapped_env.length_queue` respectively.
可以看到,gym.wrappers.RecordEpisodeStatistics 在运行过程中进行统计然后在info中进行显示,这样的操作会占用一定的计算资源,如果没有必要使用则不需要使用。
===================================================
参考:
posted on 2023-05-23 23:25 Angry_Panda 阅读(662) 评论(0) 编辑 收藏 举报