def transform_observation_space(
     self,
     observation_space: spaces.Dict,
 ):
     size = self._size
     observation_space = copy.deepcopy(observation_space)
     if size:
         for key in observation_space.spaces:
             if key in self.trans_keys:
                 # In the observation space dict, the channels are always last
                 h, w = get_image_height_width(
                     observation_space.spaces[key], channels_last=True
                 )
                 if size == min(h, w):
                     continue
                 scale = size / min(h, w)
                 new_h = int(h * scale)
                 new_w = int(w * scale)
                 new_size = (new_h, new_w)
                 logger.info(
                     "Resizing observation of %s: from %s to %s"
                     % (key, (h, w), new_size)
                 )
                 observation_space.spaces[key] = overwrite_gym_box_shape(
                     observation_space.spaces[key], new_size
                 )
     return observation_space
Exemplo n.º 2
0
    def transform_observation_space(
        self,
        observation_space: spaces.Dict,
    ):
        size = self._size
        observation_space = copy.deepcopy(observation_space)
        if size:
            for key in observation_space.spaces:
                if (key in self.trans_keys and
                        observation_space.spaces[key].shape[-3:-1] != size):
                    h, w = get_image_height_width(
                        observation_space.spaces[key], channels_last=True)
                    logger.info(
                        "Center cropping observation size of %s from %s to %s"
                        % (key, (h, w), size))

                    observation_space.spaces[key] = overwrite_gym_box_shape(
                        observation_space.spaces[key], size)
        return observation_space
Exemplo n.º 3
0
 def transform_observation_space(
     self,
     observation_space: SpaceDict,
 ):
     r"""Transforms the target UUID's sensor obs_space so it matches the new shape (EQ_H, EQ_W)"""
     # Transforms the observation space to of the target UUID
     observation_space = copy.deepcopy(observation_space)
     for i, key in enumerate(self.target_uuids):
         assert (
             key in observation_space.spaces
         ), f"{key} not found in observation space: {observation_space.spaces}"
         c = self.cubemap_length
         logger.info(
             f"Overwrite sensor: {key} from size of ({c}, {c}) to equirect image of {self.eq_shape} from sensors: {self.sensor_uuids[i*6:(i+1)*6]}"
         )
         if (c, c) != self.eq_shape:
             observation_space.spaces[key] = overwrite_gym_box_shape(
                 observation_space.spaces[key], self.eq_shape)
     return observation_space
Exemplo n.º 4
0
 def transform_observation_space(
     self,
     observation_space: spaces.Dict,
 ):
     r"""Transforms the target UUID's sensor obs_space so it matches the new shape (H, W)"""
     # Transforms the observation space to of the target UUID
     for i, key in enumerate(self.target_uuids):
         assert (
             key in observation_space.spaces
         ), f"{key} not found in observation space: {observation_space.spaces}"
         h, w = get_image_height_width(observation_space.spaces[key],
                                       channels_last=True)
         in_len = self.converter.input_len
         logger.info(
             f"Overwrite sensor: {key} from size of ({h}, {w}) to image of"
             f" {self.img_shape} from sensors: {self.sensor_uuids[i*in_len:(i+1)*in_len]}"
         )
         if (h, w) != self.img_shape:
             observation_space.spaces[key] = overwrite_gym_box_shape(
                 observation_space.spaces[key], self.img_shape)
     return observation_space
Exemplo n.º 5
0
 def transform_observation_space(
     self,
     observation_space: spaces.Dict,
 ):
     r"""Transforms the target UUID's sensor obs_space so it matches the new shape (FISH_H, FISH_W)"""
     # Transforms the observation space to of the target UUID
     for i, key in enumerate(self.target_uuids):
         assert (
             key in observation_space.spaces
         ), f"{key} not found in observation space: {observation_space.spaces}"
         h, w = get_image_height_width(observation_space.spaces[key],
                                       channels_last=True)
         assert (
             h == w
         ), f"cubemap height and width must be the same, but is {h} and {w}"
         logger.info(
             f"Overwrite sensor: {key} from size of ({h}, {w}) to fisheye image of {self.fish_shape} from sensors: {self.sensor_uuids[i*6:(i+1)*6]}"
         )
         if (h, w) != self.fish_shape:
             observation_space.spaces[key] = overwrite_gym_box_shape(
                 observation_space.spaces[key], self.fish_shape)
     return observation_space