l5kit.sampling package

l5kit.sampling.generate_agent_sample(state_index: int, frames: numpy.ndarray, all_agents: numpy.ndarray, selected_track_id: Optional[int], raster_size: Tuple[int, int], pixel_size: numpy.ndarray, ego_center: numpy.ndarray, history_num_frames: int, history_step_size: int, future_num_frames: int, future_step_size: int, 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.

Arguments:

state_index {int} – The anchor frame index, i.e. the “current” timestep frames {np.ndarray} – The whole frames array, can be numpy array or a zarr array. all_agents {np.ndarray} – The whole agents 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_states {int} – Amount of history frames to draw into the rasters., history_step_size {int} – Steps to take between frames, can be used to subsample history frames. future_num_states {int} – Amount of history frames to draw into the rasters. future_step_size {int} – Steps to take between targets into the future. 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 {Rasterizer} – Rasterizer of some sort that draws a map image.

voxel_shape (Tuple[int, int]): Desired output raster dimensions voxel_size (np.ndarray): Size of one pixel in the real world voxel_ego_center (np.ndarray): Where in the raster to draw the ego, [0.5,0.5] would be the center history_num_states (int): Amount of history frames to draw into the rasters., history_step_size (int): Steps to take between frames, can be used to subsample history frames. future_num_states (int): Amount of history frames to draw into the rasters. future_step_size (int): Steps to take between targets into the future. 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.

Keyword Arguments:

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 (default: {None})

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:

input_im (np.ndarray): Input raster to be used as input of a learned prediction or planning model. future_coords_offset (np.ndarray): The offset from the current state in terms of translation, currently

expressed in pixels (to be changed).

future_yaws_offset (np.ndarray): The yaw offset of future frames from the current frame. future_availability (np.ndarray): A binary mask of future_num_states length whether there is a valid target for that state. If you sample near the end of a scene, this may contain zeroes.

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.