pythongoogle-colaboratoryreinforcement-learning

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. I am not bothered about visualising the training I just want colab to do the bulk of the work.

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:

---------------------------------------------------------------------------
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. 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.

Thanks in advance


Solution

  • 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

    Unpack the .rar file then unzip the HC Roms and Roms folders.

    Next upload the folders to colab or to your Google Drive and then link it to your 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.

    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.

    Hope this helps people.