l5kit.sampling package

l5kit.sampling.generate_agent_sample(state_index: int, frames: numpy.ndarray, agents: numpy.ndarray, tl_faces: numpy.ndarray, selected_track_id: Optional[int], render_context: l5kit.rasterization.render_context.RenderContext, history_num_frames: int, future_num_frames: int, step_time: float, filter_agents_threshold: float, rasterizer: Optional[l5kit.rasterization.rasterizer.Rasterizer] = None, perturbation: Optional[l5kit.kinematic.perturbation.Perturbation] = None) → dict
Generates the inputs and targets to train a deep prediction model. A deep prediction model takes as input

the state of the world (here: an image we will call the “raster”), and outputs where that agent will be some seconds into the future.

This function has a lot of arguments and is intended for internal use, you should try to use higher level classes and partials that use this function.

Args:

state_index (int): The anchor frame index, i.e. the “current” timestep in the scene frames (np.ndarray): The scene frames array, can be numpy array or a zarr array agents (np.ndarray): The full agents array, can be numpy array or a zarr array tl_faces (np.ndarray): The full traffic light faces array, can be numpy array or a zarr array selected_track_id (Optional[int]): Either None for AV, or the ID of an agent that you want to predict the future of. This agent is centered in the raster and the returned targets are derived from their future states. raster_size (Tuple[int, int]): Desired output raster dimensions pixel_size (np.ndarray): Size of one pixel in the real world ego_center (np.ndarray): Where in the raster to draw the ego, [0.5,0.5] would be the center history_num_frames (int): Amount of history frames to draw into the rasters future_num_frames (int): Amount of history frames to draw into the rasters step_time (float): seconds between consecutive steps filter_agents_threshold (float): Value between 0 and 1 to use as cutoff value for agent filtering based on their probability of being a relevant agent rasterizer (Optional[Rasterizer]): Rasterizer of some sort that draws a map image perturbation (Optional[Perturbation]): Object that perturbs the input and targets, used

to train models that can recover from slight divergence from training set data

Raises:

ValueError: A ValueError is returned if the specified selected_track_id is not present in the scene or was filtered by applying the filter_agent_threshold probability filtering.

Returns:

dict: a dict object with the raster array, the future offset coordinates (meters), the future yaw angular offset, the future_availability as a binary mask

l5kit.sampling.get_future_slice(frame_index: int, future_num_states: int, future_step_size: int) → slice

Given a frame index and future settings returns a slice that returns the given data in the right order. Note that this history returned starts with the most “recent” frame first (e.g. current_frame``+``future_step_size).

Example: frame_index=20, future_num_states=2, future_step_size=2 would return a slice for frame index 22, 24.

Parameters
  • state_index (int) – The “anchor” frame index you want to sample from

  • future_num_states (int) – Number of future frames.

  • future_step_size (int) – How many frames to step for each future step.

Raises

IndexError – Returned when future_step_size is an invalid value (e.g. 0).

Returns

slice – Slice that when applied to an array returns the future frames in the right order.

l5kit.sampling.get_history_slice(frame_index: int, history_num_states: int, history_step_size: int, include_current_state: bool = False) → slice

Given a frame index and history settings returns a slice that returns the given data in the right order. Note that this history returned starts with the most “recent” frame first (i.e. reverse in time as it’s history).

Example: frame_index=20, history_num_frames=2, history_step_size=2, include_current_state=True would return a slice for frame index 20, 18, 16.

Parameters
  • state_index (int) – The “anchor” frame index you want to sample from

  • history_num_states (int) – Number of history frames (not including the current frame).

  • history_step_size (int) – How many frames to step for each history step.

Keyword Arguments

include_current_state (bool) – Whether the slice should include frame_index (default: {False})

Raises

IndexError – Returned when history_step_size is an invalid value (e.g. 0).

Returns

slice – Slice that when applied to an array returns the history frames in the right order.