l5kit.rasterization package¶
- class l5kit.rasterization.BoxRasterizer(render_context: l5kit.rasterization.render_context.RenderContext, filter_agents_threshold: float, history_num_frames: int, render_ego_history: bool = True)¶
Bases:
l5kit.rasterization.rasterizer.Rasterizer
- num_channels() int ¶
- rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray ¶
Generate raster image by rendering Ego & Agents as bounding boxes on the raster image. Ego & Agents from different past frame are rendered at different image channel.
- Parameters
history_frames – A list of past frames to be rasterized
history_agents – A list of agents from past frames to be rasterized
history_tl_faces – A list of traffic light faces from past frames to be rasterized
agent – The selected agent to be rendered as Ego, if it is None the AV will be rendered as Ego
- Returns
An raster image of size [2xN] with Ego & Agents rendered as bounding boxes, where N is number of history frames
- to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray ¶
This function is used to get an rgb image where agents further in the past have faded colors.
- Parameters
in_im – The output of the rasterize function
kwargs – This can be used for additional customization (such as colors)
- Returns
An RGB image with agents and ego coloured with fading colors
- class l5kit.rasterization.Rasterizer¶
Bases:
abc.ABC
Base class for something that takes a single state of the world, and outputs a (multi-channel) image.
- abstract num_channels() int ¶
- abstract rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray ¶
- abstract to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray ¶
- class l5kit.rasterization.RenderContext(raster_size_px: numpy.ndarray, pixel_size_m: numpy.ndarray, center_in_raster_ratio: numpy.ndarray, set_origin_to_bottom: bool)¶
Bases:
object
- raster_from_world(position_m: numpy.ndarray, angle_rad: float) numpy.ndarray ¶
Return a matrix to convert a pose in world coordinates into raster coordinates
- Parameters
render_context (RenderContext) – the context for rasterisation
position_m (np.ndarray) – XY position in world coordinates
angle_rad (float) – rotation angle in world coordinates
- Returns
a transformation matrix from world coordinates to raster coordinates
- Return type
(np.ndarray)
- class l5kit.rasterization.SatBoxRasterizer(render_context: l5kit.rasterization.render_context.RenderContext, filter_agents_threshold: float, history_num_frames: int, map_im: numpy.ndarray, world_to_aerial: numpy.ndarray, interpolation: int = 1, render_ego_history: bool = True)¶
Bases:
l5kit.rasterization.rasterizer.Rasterizer
Combine a Satellite and a Box Rasterizers into a single class
- num_channels() int ¶
- rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray ¶
- to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray ¶
- class l5kit.rasterization.SatelliteRasterizer(render_context: l5kit.rasterization.render_context.RenderContext, map_im: numpy.ndarray, world_to_aerial: numpy.ndarray, interpolation: int = 1)¶
Bases:
l5kit.rasterization.rasterizer.Rasterizer
This rasterizer takes a satellite image in its constructor and a transform from world coordinates to this image. When you call rasterize, it will return a crop around the agent of interest with the agent’s forward vector pointing right for the current timestep.
- num_channels() int ¶
- rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray ¶
- to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray ¶
- class l5kit.rasterization.SemBoxRasterizer(render_context: l5kit.rasterization.render_context.RenderContext, filter_agents_threshold: float, history_num_frames: int, semantic_map_path: str, world_to_ecef: numpy.ndarray, render_ego_history: bool = True)¶
Bases:
l5kit.rasterization.rasterizer.Rasterizer
Combine a Semantic Map and a Box Rasterizers into a single class
- num_channels() int ¶
- rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray ¶
- to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray ¶
- class l5kit.rasterization.SemanticRasterizer(render_context: l5kit.rasterization.render_context.RenderContext, semantic_map_path: str, world_to_ecef: numpy.ndarray)¶
Bases:
l5kit.rasterization.rasterizer.Rasterizer
Rasteriser for the vectorised semantic map (generally loaded from json files).
- num_channels() int ¶
- rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray ¶
- render_semantic_map(center_in_world: numpy.ndarray, raster_from_world: numpy.ndarray, tl_faces: numpy.ndarray) numpy.ndarray ¶
Renders the semantic map at given x,y coordinates.
- Parameters
center_in_world (np.ndarray) – XY of the image center in world ref system
raster_from_world (np.ndarray) –
- Returns
RGB raster
- Return type
np.ndarray
- to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray ¶
- class l5kit.rasterization.StubRasterizer(render_context: l5kit.rasterization.render_context.RenderContext)¶
Bases:
l5kit.rasterization.rasterizer.Rasterizer
This rasterizer doesn’t actually do anything, it returns an all-black image. Useful for testing.
- num_channels() int ¶
- rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray ¶
Just return an empty raster_size x 3 black image
- to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray ¶
Return a completely black image.
- l5kit.rasterization.build_rasterizer(cfg: dict, data_manager: l5kit.data.local_data_manager.DataManager) l5kit.rasterization.rasterizer.Rasterizer ¶
Factory function for rasterizers, reads the config, loads required data and initializes the correct rasterizer.
- Parameters
cfg (dict) – Config.
data_manager (DataManager) – Datamanager that is used to require files to be present.
- Raises
NotImplementedError – Thrown when the
map_type
read from the config doesn’t have an associated rasterizertype in this factory function. If you have custom rasterizers, you can wrap this function in your own factory –
function and catch this error. –
- Returns
Rasterizer initialized given the supplied config.
- Return type
- l5kit.rasterization.get_sat_image_crop(sat_image: numpy.ndarray, crop_size: Union[Tuple[int, int], numpy.ndarray], sat_pixel_translation: numpy.ndarray, yaw: Optional[float] = None) numpy.ndarray ¶
Crops input satellite such that
sat_pixel_translation
is centered in the image.- Parameters
sat_image (np.ndarray) – satellite image
crop_size (Union[Tuple[int, int], np.ndarray]) – size of desired crop in pixels
sat_pixel_translation (np.ndarray) – 2D or 3D vector where to center the cropped image in pixels.
- Keyword Arguments
yaw (Optional[float]) – yaw in radians, None or 0 means no rotation is applied to the output image. default: {None})
- Returns
a crop of input
sat_image
- Return type
(np.ndarray)
- l5kit.rasterization.get_sat_image_crop_scaled(sat_image: numpy.ndarray, crop_size: Union[Tuple[int, int], numpy.ndarray], sat_pixel_translation: numpy.ndarray, yaw: Optional[float] = None, sat_pixel_scale: float = 1.0, pixel_size: float = 1.0, interpolation: int = 1) numpy.ndarray ¶
- Calls get_sat_image_crop (see that function’s docs for further details), and rescales taking
into account a desired pixel size.
Example
Desired
crop_size
is 200x200, andpixel_size
is 0.5: we want an image that corresponds to 100x100 meters. This means it extracts a 33x33 image and scales it up to 200x200.- Parameters
sat_image (np.ndarray) – satellite image
crop_size (Union[Tuple[int, int], np.ndarray]) – size of desired crop in pixels
sat_pixel_translation (np.ndarray) – 2D or 3D vector where to center the cropped image in pixels.
- Keyword Arguments
yaw (Optional[float]) – yaw in radians, 0 means no rotation is applied, which generally means up is North. default: {None})
sat_pixel_scale (float) – A sat_pixel_scale of 3.0 would means that every pixel in the sat
(default (image corresponds to 3m in the real world.) – {1.0})
pixel_size (float) – [description] (default: {1.0})
interpolation (int) – [description] (default: {cv2.INTER_LINEAR})
- Returns
a crop of input
sat_image
- Return type
(np.ndarray)
- l5kit.rasterization.get_sat_image_crop_scaled_from_ecef(sat_image: numpy.ndarray, crop_size: Union[Tuple[int, int], numpy.ndarray], ecef_translation: numpy.ndarray, ecef_to_sat: numpy.ndarray, **kwargs: Any) numpy.ndarray ¶
Utility function, calls get_sat_image_crop_scaled, see that function for more details on additional keyword arguments (such as
yaw
).- Parameters
sat_image (np.ndarray) – satellite image
crop_size (Union[Tuple[int, int], np.ndarray]) – size of desired crop in pixels
ecef_translation (np.ndarray) – 2D or 3D vector where to center the cropped image
ecef_to_sat (np.ndarray) – transform from ECEF to satellite image space
- Returns
np.ndarray – a crop of satellite_image
Submodules¶
- l5kit.rasterization.box_rasterizer module
- l5kit.rasterization.rasterizer module
- l5kit.rasterization.rasterizer_builder module
- l5kit.rasterization.render_context module
- l5kit.rasterization.sat_box_rasterizer module
- l5kit.rasterization.satellite_image module
- l5kit.rasterization.satellite_rasterizer module
- l5kit.rasterization.sem_box_rasterizer module
- l5kit.rasterization.semantic_rasterizer module
- l5kit.rasterization.stub_rasterizer module