【问题标题】:Running gym atari in google colab?在google colab中运行gym atari?
【发布时间】:2021-08-20 19:53:01
【问题描述】:

所以我希望使用 GPU/TPU 在 colab 上训练一个模型,因为我的本地机器没有。我不介意将培训可视化,我只想让 colab 完成大部分工作。

将我的 .ipynb 导入 colab 并在我尝试使用任何 atari 游戏创建环境时立即运行时,我收到错误:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-21-8d6f8581e7f9> in <module>()
----> 1 env = gym.make('SpaceInvaders-v0')
      2 height, width, channels = env.observation_space.shape
      3 actions = env.action_space.n
      4 
      5 model = build_model(height,width, channels,actions)

4 frames
/usr/local/lib/python3.7/dist-packages/atari_py/games.py in get_game_path(game_name)
     18     path = os.path.join(_games_dir, game_name) + ".bin"
     19     if not os.path.exists(path):
---> 20         raise Exception('ROM is missing for %s, see https://github.com/openai/atari-py#roms for instructions' % (game_name,))
     21     return path
     22 

Exception: ROM is missing for space_invaders, see https://github.com/openai/atari-py#roms for instructions

在本地我遇到了这个问题,并通过 github 上的步骤来修复它,但我似乎无法让 colab 做类似的事情。我在网上找到了大量的教程,它们都可以正常工作,当我运行他们的 colabs 时,我遇到了同样的问题,所以我不知道该怎么做。

提前致谢

【问题讨论】:

    标签: python google-colaboratory reinforcement-learning


    【解决方案1】:

    有一个方便的 AutoROM 包,您可以使用它来自动安装 ROM。只需在任何 Jupyter notebook、Colab notebook 或 Kaggle 内核中运行以下命令:

    %pip install -U gym>=0.21.0
    %pip install -U gym[atari,accept-rom-license]
    

    详情:

    1. 使用 %pip 而不是 !pip 可确保将包安装到与运行笔记本的 Python 环境相同的 Python 环境中。

    2. accept-rom-license 选项安装包含AutoROM 命令的autorom 包。它还使用--accept-license 选项自动运行此命令。如果您在没有此选项的情况下运行它,您会收到以下消息,因此请注意。我的感觉是可以将它们用于研究和教育目的,但我不是律师:

      AutoROM will download the Atari 2600 ROMs.
      They will be installed to:
          [...]/site-packages/AutoROM/roms
      
      Existing ROMs will be overwritten.
      
      I own a license to these Atari 2600 ROMs.
      I agree to not distribute these ROMs and wish to proceed: [Y/n]:
      
    3. 运行AutoROM --help 以获得更多选项。

    【讨论】:

      【解决方案2】:

      所以我找到了解决方案。您首先需要从http://www.atarimania.com/rom_collection_archive_atari_2600_roms.html下载roms

      解压 .rar 文件,然后解压 HC Roms 和 Roms 文件夹。

      接下来将文件夹上传到 colab 或您的 Google 云端硬盘,然后将其链接到您的 colab。

      从这里运行:

      !python -m atari_py.import_roms <path to Rom folder>
      

      我只需要导入 ROMS 文件夹,但取决于您想要的环境,您可能还必须为 HC ROMS 运行它。

      让 colab 做它的事情,然后尝试再次制作 env,它应该可以工作,让它运行 DQN 大约 6 小时,没有任何问题。

      希望这对人们有所帮助。

      【讨论】:

        猜你喜欢
        • 2017-05-21
        • 1970-01-01
        • 2019-07-14
        • 2020-10-18
        • 1970-01-01
        • 2022-12-14
        • 1970-01-01
        • 2020-09-26
        • 2021-05-31
        相关资源
        最近更新 更多