def transform_observation_space(
     self,
     observation_space: SpaceDict,
 ):
     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
 def observation_space(self):
     obs = super().observation_space
     # Extra keys "time since stop", duration
     new_obs = Box(low=-3.0,
                   high=3.0,
                   shape=(obs.shape[0] + 2, ),
                   dtype=np.float32)
     # new_obs = Box(low=-3.0, high=3.0, shape=(obs.shape[0],), dtype=np.float32)
     return Dict({"obs": new_obs, "expert_action": self.action_space})
Beispiel #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
Beispiel #4
0
    def transform_observation_space(
        self,
        observation_space: SpaceDict,
    ):
        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
 def transform_observation_space(
     self,
     observation_space: SpaceDict,
 ):
     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