简体   繁体   English

在google colab中运行gym atari?

[英]Running gym atari in google colab?

So I am looking to train a model on colab using a GPU/TPU as my local machine doesn't have one.因此,我希望使用 GPU/TPU 在 colab 上训练 model,因为我的本地机器没有。 I am not bothered about visualising the training I just want colab to do the bulk of the work.我不介意将培训可视化,我只想让 colab 完成大部分工作。

When importing my.ipynb into colab and running as soon as i attempt to make an env using any of the atari games i get the error:将 my.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

Locally I had this issue and went through the steps on the github to fix it which worked but I cannot seem to get colab to do a similar thing.在本地,我遇到了这个问题,并通过 github 上的步骤来修复它,但我似乎无法让 colab 做类似的事情。 I have found tons of tutorials online where it just works and when I run their colabs I get the same issue so I am at a bit of a loss as to what to do.我在网上找到了大量的教程,它可以正常工作,当我运行他们的 colabs 时,我遇到了同样的问题,所以我不知道该怎么做。

Thanks in advance提前致谢

So I have found a solution.所以我找到了解决方案。 You will first need to download the roms from http://www.atarimania.com/rom_collection_archive_atari_2600_roms.html您首先需要从http://www.atarimania.com/rom_collection_archive_atari_2600_roms.html下载 rom

Unpack the.rar file then unzip the HC Roms and Roms folders.解压 .rar 文件,然后解压 HC Roms 和 Roms 文件夹。

Next upload the folders to colab or to your Google Drive and then link it to your colab.接下来将文件夹上传到 colab 或您的 Google Drive,然后将其链接到您的 colab。

From here run:从这里运行:

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

I only had to import the ROMS folder but dependening on the env you want you may have to run it for the HC ROMS as well.我只需要导入 ROMS 文件夹,但取决于您想要的环境,您可能还必须为 HC ROMS 运行它。

Let colab do its thing then try making the env again and it should work, had it running a DQN for about 6 hours no with no issues.让 colab 做它的事情,然后尝试再次制作 env,它应该可以工作,让它运行 DQN 大约 6 个小时,没有任何问题。

Hope this helps people.希望这对人们有所帮助。

There's a handy AutoROM package that you can use to install the ROMs automatically.有一个方便的 AutoROM package,您可以使用它来自动安装 ROM。 Just run the following commands in any Jupyter notebook, Colab notebook or Kaggle kernel:只需在任何 Jupyter notebook、Colab notebook 或 Kaggle kernel 中运行以下命令:

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

Details:细节:

  1. Using %pip instead of !pip ensures that the package gets installed into the same Python environment as the one your notebook is running in.使用%pip而不是!pip可确保 package 安装到与您的笔记本电脑运行的环境相同的 Python 环境中。

  2. The accept-rom-license option installs the autorom package which includes the AutoROM command. accept-rom-license选项安装autorom package,其中包括AutoROM命令。 It also runs this command automatically with the --accept-license option.它还使用--accept-license选项自动运行此命令。 If you run it without this option, you get the following message, so be warned.如果您在没有此选项的情况下运行它,您会收到以下消息,因此请注意。 My feeling is that it's okay to use them for research and educational purposes, but I'm not a lawyer:我的感觉是可以将它们用于研究和教育目的,但我不是律师:

     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. Run AutoROM --help for more options.运行AutoROM --help以获得更多选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM