gtoubassi / dqn-atari

A TensorFlow based implementation of the DeepMind Atari playing "Deep Q Learning" agent that works reasonably well
91 stars 29 forks source link

Hi Gtoubassi #3

Closed sasforce closed 6 years ago

sasforce commented 6 years ago

Dear Gtoubassi Thank you for your reply. I have downloaded a game ROM of space invaders. I followed the running instructions from the readme file, but something wrong happened, as the following demonstrating. moxing@moxing-OptiPlex-9020:~/Prj/RL/DQN/dqn-atari$ python ./play_atari.py ~/space_invaders.bin | tee train.log A.L.E: Arcade Learning Environment (version 0.6.0) [Powered by Stella] Use -help for help screen. Warning: couldn't load settings file: ./ale.cfg Traceback (most recent call last): File "./play_atari.py", line 37, in <module> Arguments: Namespace(compress_replay=False, eval_epoch_steps=125000, learning_rate=0.00025, model=None, normalize_weights=True, observation_steps=50000, prioritized_replay=False, replay_capacity=1000000, rom='/home/moxing/space_invaders.bin', save_model_freq=10000, screen_capture_freq=250, target_model_update_freq=10000, train_epoch_steps=250000) environment = AtariEnvironment(args, baseOutputDir) File "/home/moxing/Prj/RL/DQN/dqn-atari/atari_environment.py", line 27, in __init__ self.ale.loadROM(args.rom) File "/home/moxing/anaconda3/lib/python3.6/site-packages/ale_python_interface/ale_python_interface.py", line 138, in loadROM ale_lib.loadROM(self.obj, rom_file) ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type I put the ROM file and the py file in the same folder, and I input the running command in the pytharm's terminal. What the problems are? Could you please help me out? Sincerely Luo

gtoubassi commented 6 years ago

Hi Luo! This is caused by the fact that the code is expecting python 2.7 and you are using python 3. the easiest thing is to get a python2.7 environment running. However porting the code to 3 is pretty easy if you want to do that. For example the issue you are hitting in this bug is that in python3 strings are unicode by default vs bytes, which doesn't work when interacting with the atari emulator (which uses native code). So you need to explicitly convert the rom name to bytes. So change this line:

    self.ale.loadROM(args.rom)

to self.ale.loadROM(args.rom.encode())

I think

You may hit other lines of code where I'm calling "print 'foo'" vs "print('foo')" but those should be easy to bang through.

Let me know if you have any issues. I'm also happy to take a PR from you to upgrade this :)

sasforce commented 6 years ago

Hi Gtoubassi Sorry, I have been busy these day, and thank you for you replay, that was very explicit. It is very kind of you. I modified the code as your instructions, but another errors happened:

File "./play_atari.py", line 103, in aveScore = runEpoch(args.train_epoch_steps) # train File "./play_atari.py", line 72, in runEpoch reward, state, isTerminal = environment.step(action) File "/home/moxing/Prj/RL/DQN/dqn-atari/atari_environment.py", line 84, in step self.ale.saveScreenPNG(dir + '/frame-%06d.png' % (self.getEpisodeFrameNumber())) File "/home/moxing/anaconda3/lib/python3.6/site-packages/ale_python_interface/ale_python_interface.py", line 266, in saveScreenPNG return ale_lib.saveScreenPNG(self.obj, filename) ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

So, how can I deal with it? Sincerely Luo

gtoubassi commented 6 years ago

Hi Luo. This looks like the same issue where we are passing a string across the boundary into native code of the arcade learning environment (ale). Basically any calls in atari_environment.py that pass a string to self.ale need to be converted to bytes via the .encode() method. So in this case try changing:

self.ale.saveScreenPNG(dir + '/frame-%06d.png' % (self.getEpisodeFrameNumber()))

to

filename = dir + '/frame-%06d.png' % (self.getEpisodeFrameNumber()) self.ale.saveScreenPNG(filename.encode())

Alternatively you could just comment that out as its simply a logging mechanism for writing out game frames so you can see what the agent is doing (or create a movie from it).

gtoubassi commented 6 years ago

Will close this issue for now but feel free to reopen or open a new one if there are other questions!

sasforce commented 6 years ago

Hi Gtoubassi Thank you for your replying again, and I solved this problem, just like you said. Thank you for your help again.