Example #1
0
    def preprocess(self, img):
        """
        Compute image operations to generate state representation
        """
        # TODO: replace scikit image with opencv
        # input shape: 300, 300, 3
        img = transform.resize(img, self.config['resolution'], mode='reflect')
        img = img.astype(np.float32)

        if self.config['grayscale']:
            img = rgb2gray(img)  #3 dims  1 channel
            img = np.moveaxis(img, 2, 0)

        elif self.use_priors:
            img = np.moveaxis(img, 2, 0)
            img = torch.Tensor(img).unsqueeze(0).to(self.device)

            if self.priors == 'manual':
                img = multi_representation_transform(
                    img / 255., self.mode)  # 3 dims, tensor, no cuda
            elif self.priors == 'max_cover':
                img = max_coverage_featureset_transform(
                    img / 255., self.k)  # 3 dims, tensor, no cuda
            else:
                raise NotImplementedError
            img = img.squeeze(0)

        else:
            img = np.moveaxis(img, 2, 0)  # 4 dims

        return img
Example #2
0
 def preprocess(self, img):
     """
     Compute image operations to generate state representation
     """
     # TODO: replace scikit image with opencv
     img = transform.resize(img, self.config['resolution'], mode='reflect')
     img = img.astype(np.float32)
     if self.observation_space.shape[0] == 1:
         img = rgb2gray(img)
     img = np.moveaxis(img, 2, 0)
     return img