Skip to content

Commit

Permalink
[Update atari_preprocessing.py]: Remove FireReset (#1661)
Browse files Browse the repository at this point in the history
* Update atari_preprocessing.py

* Update test_atari_preprocessing.py

* Update test_atari_preprocessing.py
  • Loading branch information
zuoxingdong authored and pzhokhov committed Oct 18, 2019
1 parent f610d54 commit 8962984
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
7 changes: 0 additions & 7 deletions gym/wrappers/atari_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class AtariPreprocessing(gym.Wrapper):
Specifically:
* NoopReset: obtain initial state by taking random number of no-ops on reset.
* FireReset: take action on reset for environments that are fixed until firing.
* Frame skipping: 4 by default
* Max-pooling: most recent two observations
* Termination signal when a life is lost: turned off by default. Not recommended by Machado et al. (2018).
Expand Down Expand Up @@ -105,12 +104,6 @@ def reset(self, **kwargs):
if done:
self.env.reset(**kwargs)

# FireReset
action_meanings = self.env.unwrapped.get_action_meanings()
if action_meanings[1] == 'FIRE' and len(action_meanings) >= 3:
self.env.step(1)
self.env.step(2)

self.lives = self.ale.lives()
if self.grayscale_obs:
self.ale.getScreenGrayscale(self.obs_buffer[0])
Expand Down
16 changes: 9 additions & 7 deletions gym/wrappers/test_atari_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ def test_atari_preprocessing_grayscale(env_fn):
env1 = env_fn()
env2 = AtariPreprocessing(env_fn(), screen_size=84, grayscale_obs=True, frame_skip=1, noop_max=0)
env3 = AtariPreprocessing(env_fn(), screen_size=84, grayscale_obs=False, frame_skip=1, noop_max=0)
env1.reset()
# take these steps to imitate actions of FireReset logic
env1.step(1)
obs1 = env1.step(2)[0]
env1.seed(0)
env2.seed(0)
env3.seed(0)
obs1 = env1.reset()
obs2 = env2.reset()
obs3 = env3.reset()
assert obs1.shape == (210, 160, 3)
assert obs2.shape == (84, 84)
assert obs3.shape == (84, 84, 3)
np.testing.assert_allclose(obs3, cv2.resize(obs1, (84, 84), interpolation=cv2.INTER_AREA))
assert np.allclose(obs3, cv2.resize(obs1, (84, 84), interpolation=cv2.INTER_AREA))
obs3_gray = cv2.cvtColor(obs3, cv2.COLOR_RGB2GRAY)
# the edges of the numbers do not render quite the same in the grayscale, so we ignore them
np.testing.assert_allclose(obs2[10:], obs3_gray[10:])
assert np.allclose(obs2[10:38], obs3_gray[10:38])
# the paddle also do not render quite the same
assert np.allclose(obs2[44:], obs3_gray[44:])

env1.close()
env2.close()
Expand All @@ -53,4 +55,4 @@ def test_atari_preprocessing_scale(env_fn):
assert (0 <= obs).all() and (obs <= max_obs).all(), 'Obs. must be in range [0,{}]'.format(max_obs)
step_i += 1

env.close()
env.close()

0 comments on commit 8962984

Please sign in to comment.