コード例 #1
0
ファイル: preprocessors.py プロジェクト: stefanbschneider/ray
 def transform(self, observation: TensorType) -> np.ndarray:
     """Downsamples images from (210, 160, 3) by the configured factor."""
     self.check_shape(observation)
     scaled = observation[25:-25, :, :]
     if self._dim < 84:
         scaled = resize(scaled, height=84, width=84)
     # OpenAI: Resize by half, then down to 42x42 (essentially mipmapping).
     # If we resize directly we lose pixels that, when mapped to 42x42,
     # aren't close enough to the pixel boundary.
     scaled = resize(scaled, height=self._dim, width=self._dim)
     if self._grayscale:
         scaled = scaled.mean(2)
         scaled = scaled.astype(np.float32)
         # Rescale needed for maintaining 1 channel
         scaled = np.reshape(scaled, [self._dim, self._dim, 1])
     if self._zero_mean:
         scaled = (scaled - 128) / 128
     else:
         scaled *= 1.0 / 255.0
     return scaled
コード例 #2
0
ファイル: atari_wrappers.py プロジェクト: smorad/ray
 def observation(self, frame):
     frame = rgb2gray(frame)
     frame = resize(frame, height=self.height, width=self.width)
     return frame[:, :, None]