def preprocess(self, screen, new_game=False):
luminance = screen.astype('float32').mean(2) # no need in true grayscale, just take mean
# crop top/bottom Atari specific borders
if self.env.spec.id == 'SpaceInvaders-v0':
# crop only bottom in SpaceInvaders, due to flying object at the top of the screen
luminance = luminance[:-15, :]
else:
luminance = luminance[36:-15, :]
# convert into [0.0; 1.0]
s = imresize(luminance, (self.W, self.H)).astype('float32') * (1. / 255)
s = s.reshape(1, s.shape[0], s.shape[1], 1)
if new_game or self.stacked_s is None:
self.stacked_s = np.repeat(s, self.memlen, axis=3)
else:
self.stacked_s = np.append(s, self.stacked_s[:, :, :, :self.memlen - 1], axis=3)
return self.stacked_s
评论列表
文章目录