目录

  • 参考网页
  • 重要概念
    • gym
    • Atari
    • ALE
  • 安装
    • Hello world
  • 环境
  • gym的历史版本
    • 总结
  • 扩展知识:ALE相关
    • 说明文档
    • 单靠ALE开发强化学习代码
    • 与gym结合使用
    • 安装ROM
    • 录制视频

参考网页

Gym Documentation

  • 可以搜索函数用法
  • 可以查看不同环境输出的具体定义
  • 更像是真正的说明文档
  • 从github上指路而来

Gym: A toolkit for developing and comparing reinforcement learning algorithms

  • 一些简单的介绍
  • 更像是广告页

https://github.com/openai/gym

  • github页
  • 也有简单的说明

Gym安装Atari环境(Windows,Linux适用)_李子树_的博客-CSDN博客

重要概念

gym

  • The gym library is a collection of test problems — environments — that you can use to work out your reinforcement learning algorithms. These environments have a shared interface, allowing you to write general algorithms.
  • 可以理解为提供了调用的统一接口
  • 自带就有一些基本的小游戏(或者称之为环境),包括classical control,box2d,mujoco,toytext等类别的一些小游戏,具体游戏名可以去…\Lib\site-packages\gym\envs下相应的文件夹下查看,或者去…\Lib\site-packages\gym\envs\registration.py文件内查看

Atari

  • 游戏开发商雅达利(Atari),在这里是指相应的一系列游戏

ALE

  • Arcade Learning Environment

    • Arcade,是电玩街机。
  • The Arcade Learning Environment (ALE) is a simple framework that allows researchers and hobbyists to develop AI agents for Atari 2600 games. It is built on top of the Atari 2600 emulator Stella and separates the details of emulation from agent design.
  • Native support for OpenAI Gym.
  • 对应的安装包是ale-py
    • 取代的是atari-py
  • What’s the difference between the Atari environments in OpenAI Gym and the ALE?
    • The environments provided in Gym are built on the ALE. It just provides a different API to the ALE. As of ALE 0.7 OpenAI Gym now uses ale-py and so there’s no difference between using ale-py and Gym.

安装

pip install gym

  • 安装基础版的gym
  • Successfully installed cloudpickle-2.0.0 gym-0.23.1 gym-notices-0.0.6 numpy-1.22.3
  • 在envs文件夹下包含有classical control的5款游戏;box2d的4款游戏;mujoco的12+款游戏;toy_text的5款游戏

pip install gym[atari]

  • 除了安装gym外,还回安装ale-py

pip install gym[all]

  • 会安装许多其他的包,包括box2d-py,opencv-python,ale-py,mujoco-py,pygame。直接安装会报错,提示是mujoco-py必须单独安装,mujoco-py的安装有点麻烦,此处不再探索。

Hello world

import gymenv = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):env.render()env.step(env.action_space.sample())  # take a random action
env.close()

环境

gym.make(id)中id的命名方式是*[username/](env-name)-v(version)*

from gym import envs
for env in envs.registry.all():print(env.id)

输出结果

并不是所有的输出拿来都能用(主要是Atari相关的环境,有名字但是没有包的)

As of Gym v0.20 and onwards all Atari environments are provided via ale-py. We do recommend using the new v5 environments in the ALE namespace:

import gymenv = gym.make('ALE/Breakout-v5')

gym的历史版本

从0.20开始,gym转而用ale-py了,这里测试019版本时期gym的效果

pip install gym==0.19.0
pip install atari_py==0.2.6

0.19版本的gym和最新版的区别不是很大

安装0.2.6版本的atari,相关目录下会有需要的ROM。

但是测试时会报错

Could not find module ‘D:\02 Python Envs\old_gym_test\lib\site-packages\atari_py\ale_interface\ale_c.dll’ (or one of its dependencies). Try using the full path with constructor syntax.

网络上查看主要有三种解决思路:

Could not find module \atari_py\ale_interface\ale_c.dll (or one of its dependencies)

  • 在windows上安装一些内容

    ‘module could not be found’ when running gym.make for atari environment. · Issue #1726 · openai/gym

    • 试过,没成功
  • 使用conda进行安装

    • conda install -c conda-forge atari_py
    • 没试
  • 下载缺失的文件到需要的文件加

    • 确实解决了
    • 只是显示的界面很小,速度很快

总结

总的来看,老版gym+atari-py的组合和新版gym+ale-py的区别主要在

  1. 新版组合想要用Atari的Rom时,需要自己下载

  2. 使用新版的gym时,调用atari游戏时不管是不是v5版本的,都要依照ale-py给出的渲染模式,即在程序创建环境时制定render_mode,后续程序中不再使用render函数

    # 新版
    import gymenv = gym.make('Breakout-v0', render_mode='human')
    env.reset()
    for _ in range(10000):result = env.step(env.action_space.sample())  # take a random action
    env.close()
    
    # 老版
    import gymenv = gym.make('Breakout-v0')
    env.reset()
    for _ in range(10000):env.render()result = env.step(env.action_space.sample())  # take a random action
    env.close()
    

扩展知识:ALE相关

说明文档

Arcade-Learning-Environment/docs at master · mgbellemare/Arcade-Learning-Environment

只能说非常不好找!这个包并没有一个很完善的官方网站。

单靠ALE开发强化学习代码

从上面的说明文档中找到的一段示例代码,说明ale-py本身该怎么用

import sys
from random import randrange
from ale_py import ALEInterfacedef main(rom_file):ale = ALEInterface()ale.setInt('random_seed', 123)ale.loadROM(rom_file)# Get the list of legal actionslegal_actions = ale.getLegalActionSet()num_actions = len(legal_actions)total_reward = 0while not ale.game_over():a = legal_actions[randrange(num_actions)]reward = ale.act(a)total_reward += rewardprint(f'Episode ended with score: {total_reward}')if __name__ == '__main__':if len(sys.argv) < 2:print(f"Usage: {sys.argv[0]} rom_file")sys.exit()rom_file = sys.argv[1]main(rom_file)

与gym结合使用

  • The ALE now natively supports OpenAI Gym.

  • Although you could continue using the legacy environments as is we recommend using the new v5 environments

    import gym
    import ale_pyenv = gym.make('ALE/Breakout-v5')
    
  • 在创建环境时不推荐使用render,推荐使用以下做法

    import gymenv = gym.make('Breakout-v0', render_mode='rgb_array')
    env.reset()
    _, _, _, metadata = env.step(0)
    assert 'rgb_array' in metadata
    
    • The render_mode argument supports either human | rgb_array. If rgb_array is specified we’ll return the full RGB observation in the metadata dictionary returned after an agent step.
  • 在给出环境ID时,传统的方法是使用后缀加版本的方式,这些方式也还保留着;新的版本不再使用后缀了,后缀所表达的含义推荐使用关键词给出。

    • The legacy game IDs, environment suffixes -NoFrameskip, -Deterministic, and versioning -v0, -v4 remain unchanged.

    • We do suggest that users transition to the -v5 versioning which is contained in the ALE
      namespace.

    • With the new -v5 versioning we don’t support any ID suffixes such as -NoFrameskip
      or -Deterministic, instead you should configure the environment through keyword arguments as such:

      import gymenv = gym.make('ALE/Breakout-v5',obs_type='rgb',                   # ram | rgb | grayscaleframeskip=5,                     # frame skipmode=0,                           # game mode, see Machado et al. 2018difficulty=0,                     # game difficulty, see Machado et al. 2018repeat_action_probability=0.25,   # Sticky action probabilityfull_action_space=True,           # Use all actionsrender_mode=None                  # None | human | rgb_array
      )
      
    • 可以接受的命名包括

      • Pong-v0

        • PongNoFrameskip-v0
        • PongDeterministic-v0
      • Pong-v4
        • PongNoFrameskip-v0
        • PongDeterministic-v4
      • ALE/Pong-v5

安装ROM

ale-py支持的游戏在上面的说明文档有列出。

安装ale-py自带的有一个游戏叫Tetris(俄罗斯方块)。使用如下代码,结合pygame,可以绘出图像。

import gymenv = gym.make('ALE/Tetris-v5', render_mode='human')
env.reset()
for _ in range(1000):result = env.step(env.action_space.sample())  # take a random action
env.close()

安装更多的ROMs有以下方法

  • 使用官方工具ale-import-roms

    • 安装ale-py时,会在pip同文件夹下安装ale-import-roms.exe文件,如果下载好ROM后,可以在命令行中执行ale-import-roms roms/命令来安装ROM(扩展名为bin的文件)(假设roms/是存ROM的文件路径)

      • 根据各种地方看到的资料,之所以使用这个工具而不是直接将bin文件拷贝过去,应该是存在文件版本校验的问题,比如平台是否支持,版本是否对应。一个不太官方的博客有说过版本的问题:If we want to get to a place in the community where we can feel confident comparing results on these types of benchmarks we have to take a tougher stance on standardizing these small details. This is why we now require ROMs using the new ROM management tools to match a known supported ROM.
      • 在我的计算机上跑(win11),一直报RuntimeError,还没有测试这个工具使用的具体情况
    • 有一个第三方网站存在着大量的ROM,有一些教程推荐前去下载

      Atari 2600 VCS ROM Collection

  • 使用第三方包autorom

    • pip install autorom

    • AutoROM --accept-license

    • 来自于以下问答

      Error in importing environment OpenAI Gym

    • 关于AutoROM的用法,github上的readme写的很清楚

      https://github.com/Farama-Foundation/AutoROM

    • 一个问题:隔了一段时间后,忽然又找不到了?

    • 手动把autorom的文件移到了ale-py rom下面,又能找到了

    • 卸载autorom,再安装并下载ROM到默认位置,系统可以识别

录制视频

Arcade-Learning-Environment/visualization.md at master · mgbellemare/Arcade-Learning-Environment

Gym包的安装与使用(新旧版本问题,Atari游戏支持问题)相关推荐

  1. reactjs组件生命周期:componentWillReceiveProps及新旧版本生命周期钩子函数对比

    reactjs组件生命周期:componentWillReceiveProps及新旧版本生命周期钩子函数对比

  2. Intellij IDEA--取消双击shift搜索的方法(包含新旧版本)

    原文网址:Intellij IDEA--取消双击shift搜索的方法(包含新旧版本)_IT利刃出鞘的博客-CSDN博客 简介 Idea, WebStorm, Pycharm这几个Intellij的软件 ...

  3. React新旧版本生命周期对比

    React新旧版本生命周期对比 ❶ 过时生命周期: ① componentWillMount ② componentWillReceiveProps ③ componentWillUpdate ❷ 即 ...

  4. gym包更新升级到0.26.2版本后炼丹炉的测试代码

    关于gym包升级到0.26.2版本后炼丹炉测试代码的修改 前两天电脑有问题,重装了系统.就有了关于安装了更新后的软件包跑环境测试代码遇到的问题. 本文包版本分别为--gym version:0.26. ...

  5. 测试吃鸡游戏帧数软件,帧数猛提!新旧版本《绝地求生》实测

    引起全民吃鸡大热潮的国民级大型游戏<绝地求生:大逃杀>与17年12月21日迎来了它的首个正式版,其中最大的改动就是游戏客户端及服务器端的性能优化,通俗地说就是硬件不变的情况下游戏帧数会上涨 ...

  6. android大版本ota,Android OTA升级新旧版本任意升级

    1. Android升级到较新的版本后,想用.zip升级包升回旧的版本时,在升级时会发错.这是由于android系统时对升级文件有版本检测. 2. build/tools/releasetools/o ...

  7. ABP的新旧版本选型

    新版本  (abp vnext ) https://www.abp.io/ ABP是一个开源的应用程序框架ASP.NET基于核心的web应用程序开发,也支持开发其他类型的应用程序. 对旧版本的重写,基 ...

  8. Ubuntu新旧版本下载地址

    官网 https://ubuntu.com/ 中文网站: https://cn.ubuntu.com/ 最新版本下载 点击"下载",即可进入: https://cn.ubuntu. ...

  9. 新旧版本表格数据对比差异流程

    1.数据合并:将旧版本的数据和新版本的数据放置到同一个表格中. 2.通过vlookup(需要查找的数据,查找数据的范围,查找范围中需要的部分的列序号,false 精确查询 true 模糊查询)  两表 ...

  10. 安卓APP安装兼容性[应用是非正式发布版本, 当前设备不支持安装。]

    应用是非正式发布版本, 当前设备不支持安装 解决办法参考文章:https://blog.csdn.net/RELY_ON_YOURSELF/article/details/122856844

最新文章

  1. 在CentOS 6.3 64bit上安装最新版tsar并监控ATS 5.3
  2. 《云数据管理:挑战与机遇》2.3.3 恢复和提交
  3. 图文并茂的生产者消费者应用实例demo
  4. nat端口限制_Cisco ASA 防火墙 NAT - 基本概念
  5. depcomp: line 571: exec: g++: not found
  6. cf 1059e 思维 贪心 树
  7. 【UVA 10816】 Travel in Desert (最小瓶颈树+最短路)
  8. SQL Server【四】
  9. matplotlib mysql_matplotlib简介
  10. Centos7离线安装redis
  11. maven的pom文件出现Multiple annotations found at this line...,已解决
  12. Android 下拉刷新用法
  13. python画柱状图-Python绘制精美图表之双柱形图
  14. 男性护肤不“美白” 控油:男女有别 - 生活至上,美容至尚!
  15. sum 去重_总结leetcode上【排列问题】【组合问题】【子集问题】回溯算法去重的两种写法!...
  16. How Not to Crash #2: Mutation Exceptions 可变异常(不要枚举可变的集合)
  17. ActiveMQ 命令行启动 与 嵌入式启动、MessageListener 监听消息
  18. python 刷票_Python刷票器的简单实现
  19. glide scaletype 无效_android 自定义圆角ImageView,后设置scaleType=centerCrop无效?
  20. KNX转485模块专用配置软件使用说明书

热门文章

  1. 经典c程序100例详解
  2. 常用国家标准、行业标准、地方标准免费查阅网址,太实用了!
  3. ApacheCN 翻译/校对/笔记整理活动进度公告 2019.10.4
  4. 中登TA、自TA、分TA
  5. MSProject的使用教程
  6. windows server2008r2 管理员身份
  7. 官方发布 激情世界杯】浩海技术 GHOST XP SP3 世界杯装机特别版★用稳定压倒一切!...
  8. Python实现简单自动升级exe程序版本并自动运行
  9. 设置linux开机自动运行某条命令或程序和安装jdk(jar)
  10. Linux中设置Java程序开机自动运行