Example #1
0
 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
Example #2
0
 def observation(self, frame):
     frame = rgb2gray(frame)
     frame = resize(frame, height=self.height, width=self.width)
     return frame[:, :, None]