Beispiel #1
0
class ImageStateObservation(ObservationBase):
    """
    Use ego state info, navigation info and front cam image/top down image as input
    The shape needs special handling
    """
    IMAGE = "image"
    STATE = "state"

    def __init__(self, vehicle_config):
        config = vehicle_config
        super(ImageStateObservation, self).__init__(config)
        self.img_obs = ImageObservation(config, config["image_source"], config["rgb_clip"])
        self.state_obs = StateObservation(config)

    @property
    def observation_space(self):
        # TODO it should be specified by different vehicle
        return gym.spaces.Dict(
            {
                self.IMAGE: self.img_obs.observation_space,
                self.STATE: self.state_obs.observation_space
            }
        )

    def observe(self, vehicle: BaseVehicle):
        return {self.IMAGE: self.img_obs.observe(vehicle), self.STATE: self.state_obs.observe(vehicle)}
Beispiel #2
0
class LidarStateObservationMARound(ObservationType):
    def __init__(self, vehicle_config):
        self.state_obs = StateObservation(vehicle_config)
        super(LidarStateObservationMARound, self).__init__(vehicle_config)
        self.state_length = list(self.state_obs.observation_space.shape)[0]

    @property
    def observation_space(self):
        shape = list(self.state_obs.observation_space.shape)
        if self.config["lidar"]["num_lasers"] > 0 and self.config["lidar"][
                "distance"] > 0:
            # Number of lidar rays and distance should be positive!
            shape[0] += self.config["lidar"]["num_lasers"] + self.config[
                "lidar"]["num_others"] * self.state_length
        return gym.spaces.Box(-0.0, 1.0, shape=tuple(shape), dtype=np.float32)

    def observe(self, vehicle):
        num_others = self.config["lidar"]["num_others"]
        state = self.state_observe(vehicle)
        other_v_info = []
        if vehicle.lidar is not None:
            if self.config["lidar"]["num_others"] > 0:
                surrounding_vehicles = list(
                    vehicle.lidar.get_surrounding_vehicles())
                surrounding_vehicles.sort(
                    key=lambda v: norm(vehicle.position[0] - v.position[0],
                                       vehicle.position[1] - v.position[1]))
                surrounding_vehicles += [None] * num_others
                for tmp_v in surrounding_vehicles[:num_others]:
                    if tmp_v is not None:
                        tmp_v = tmp_v.get_vehicle()
                        other_v_info += self.state_observe(tmp_v).tolist()
                    else:
                        other_v_info += [0] * self.state_length
            other_v_info += self._add_noise_to_cloud_points(
                vehicle.lidar.get_cloud_points(),
                gaussian_noise=self.config["lidar"]["gaussian_noise"],
                dropout_prob=self.config["lidar"]["dropout_prob"])
        return np.concatenate((state, np.asarray(other_v_info)))

    def state_observe(self, vehicle):
        return self.state_obs.observe(vehicle)

    def _add_noise_to_cloud_points(self, points, gaussian_noise, dropout_prob):
        if gaussian_noise > 0.0:
            points = np.asarray(points)
            points = np.clip(
                points + np.random.normal(
                    loc=0.0, scale=gaussian_noise, size=points.shape), 0.0,
                1.0)

        if dropout_prob > 0.0:
            assert dropout_prob <= 1.0
            points = np.asarray(points)
            points[np.random.uniform(0, 1, size=points.shape) <
                   dropout_prob] = 0.0

        return list(points)
Beispiel #3
0
 def __init__(self, vehicle_config):
     config = vehicle_config
     super(ImageStateObservation, self).__init__(config)
     self.img_obs = ImageObservation(config, config["image_source"], config["rgb_clip"])
     self.state_obs = StateObservation(config)
Beispiel #4
0
 def __init__(self, vehicle_config):
     self.state_obs = StateObservation(vehicle_config)
     super(LidarStateObservationMARound, self).__init__(vehicle_config)
     self.state_length = list(self.state_obs.observation_space.shape)[0]
 def __init__(self, vehicle_config):
     self.state_obs = StateObservation(vehicle_config)
     super(LidarStateObservationMARound, self).__init__(vehicle_config)
     self.state_length = list(self.state_obs.observation_space.shape)[0]
     self.cloud_points = None
     self.detected_objects = None