PacktPublishing / Deep-Reinforcement-Learning-Hands-On

Hands-on Deep Reinforcement Learning, published by Packt
MIT License
2.81k stars 1.28k forks source link

how to save & play Atari models built with ptan? #91

Closed SpeedCoder5 closed 3 years ago

SpeedCoder5 commented 3 years ago

It really helped me to run Chapter06/03_dqn_play.py to see an example video of how the actual game played. What is the best way to go about saving Atari models built with ptan in Chapter07 and beyond and also play back a video of how they worked.

I tried merging ptan code from Chapter07 into Chapter06/03_dqn_play.py and get an error on line 42:

state_v = torch.tensor(np.array([state], copy=False)) TypeError: int() argument must be a string, a bytes-like object or a number, not 'LazyFrames'

What is LazyFrames?

SpeedCoder5 commented 3 years ago

Reading parameters like:

params = common.HYPERPARAMS['pong']

and creating the environment thusly:

env = gym.make(params['env_name'])
env = ptan.common.wrappers.wrap_dqn(env,stack_frames=4)

and modifying line 42 to:

    state_v = torch.tensor(np.array([np.array(state, copy=False)], copy=False))

resolved the issue for me. Solution for these two issues helped: