Esempio n. 1
0
def build_rasterizer(cfg: dict,
                     data_manager: DataManager,
                     debug: bool = False) -> Rasterizer:
    raster_cfg = cfg["raster_params"]
    map_type = raster_cfg["map_type"]

    if map_type == "semantic_graph":
        dataset_meta_key = raster_cfg["dataset_meta_key"]
        filter_agents_threshold = raster_cfg["filter_agents_threshold"]
        history_num_frames = cfg["model_params"]["history_num_frames"]

        render_context = RenderContext(
            raster_size_px=np.array(raster_cfg["raster_size"]),
            pixel_size_m=np.array(raster_cfg["pixel_size"]),
            center_in_raster_ratio=np.array(raster_cfg["ego_center"]),
        )

        semantic_map_filepath = data_manager.require(
            raster_cfg["semantic_map_key"])
        dataset_meta = _load_metadata(dataset_meta_key, data_manager)
        world_to_ecef = np.array(dataset_meta["world_to_ecef"],
                                 dtype=np.float64)

        return SemGraphRasterizer(render_context, filter_agents_threshold,
                                  history_num_frames, semantic_map_filepath,
                                  world_to_ecef, debug)
    else:
        return l5kit_build_rasterizer(cfg, data_manager)
    def from_cfg(cfg, data_manager):
        raster_cfg = cfg["raster_params"]
        # map_type = raster_cfg["map_type"]
        dataset_meta_key = raster_cfg["dataset_meta_key"]

        render_context = RenderContext(
            raster_size_px=np.array(raster_cfg["raster_size"]),
            pixel_size_m=np.array(raster_cfg["pixel_size"]),
            center_in_raster_ratio=np.array(raster_cfg["ego_center"]),
        )
        # filter_agents_threshold = raster_cfg["filter_agents_threshold"]
        # history_num_frames = cfg["model_params"]["history_num_frames"]

        semantic_map_filepath = data_manager.require(
            raster_cfg["semantic_map_key"])
        try:
            dataset_meta = _load_metadata(dataset_meta_key, data_manager)
            world_to_ecef = np.array(dataset_meta["world_to_ecef"],
                                     dtype=np.float64)
        except (KeyError, FileNotFoundError
                ):  # TODO remove when new dataset version is available
            world_to_ecef = get_hardcoded_world_to_ecef()

        return TLSemanticRasterizer(render_context, semantic_map_filepath,
                                    world_to_ecef)
Esempio n. 3
0
    def train_dataloader(self):
        train_cfg = cfg["train_data_loader"]

        try:
            dataset_meta = _load_metadata(train_cfg["dataset_meta_key"], dm)
            world_to_ecef = np.array(dataset_meta["world_to_ecef"],
                                     dtype=np.float64)
        except (KeyError, FileNotFoundError):
            world_to_ecef = get_hardcoded_world_to_ecef()

        semantic_map_filepath = dm.require(train_cfg["semantic_map_key"])

        rasterizer = OpenGLSemanticRasterizer(
            raster_size=train_cfg["raster_size"],
            pixel_size=train_cfg["pixel_size"],
            ego_center=train_cfg["ego_center"],
            filter_agents_threshold=0.5,
            history_num_frames=train_cfg['history_num_frames'],
            semantic_map_path=semantic_map_filepath,
            world_to_ecef=world_to_ecef,
        )

        train_zarr = ChunkedDataset(dm.require(train_cfg["key"])).open()
        train_dataset = AgentDataset(cfg, train_zarr, rasterizer)
        train_dataloader = DataLoader(
            train_dataset,
            sampler=RandomSampler(
                train_dataset,
                num_samples=cfg["train_params"]["max_num_steps"],
                replacement=True,
            ),
            batch_size=train_cfg["batch_size"],
            num_workers=train_cfg["num_workers"])
        return train_dataloader
Esempio n. 4
0
def build_rasterizer_tl(cfg: dict, data_manager: DataManager) -> Rasterizer:
    """Factory function for rasterizers, reads the config, loads required data and initializes the correct rasterizer.

    Args:
        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 rasterizer
        type 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: Rasterizer initialized given the supplied config.
    """
    raster_cfg = cfg["raster_params"]
    map_type = raster_cfg["map_type"]
    dataset_meta_key = raster_cfg["dataset_meta_key"]

    render_context = RenderContext(
        raster_size_px=np.array(raster_cfg["raster_size"]),
        pixel_size_m=np.array(raster_cfg["pixel_size"]),
        center_in_raster_ratio=np.array(raster_cfg["ego_center"]),
    )
    filter_agents_threshold = raster_cfg["filter_agents_threshold"]
    history_num_frames = cfg["model_params"]["history_num_frames"]

    semantic_map_filepath = data_manager.require(raster_cfg["semantic_map_key"])
    try:
        dataset_meta = _load_metadata(dataset_meta_key, data_manager)
        world_to_ecef = np.array(dataset_meta["world_to_ecef"], dtype=np.float64)
    except (KeyError, FileNotFoundError):  # TODO remove when new dataset version is available
        world_to_ecef = get_hardcoded_world_to_ecef()

    return SemBoxTLRasterizer(render_context, filter_agents_threshold, history_num_frames, semantic_map_filepath,
                              world_to_ecef)
Esempio n. 5
0
if __name__ == '__main__':
    os.environ["L5KIT_DATA_FOLDER"] = "./input"
    config_file = "baseline_agent_motion.yaml"
    cfg = load_config_data(f"./configs/{config_file}")

    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    dm = LocalDataManager()
    dataset_path = dm.require(cfg["train_data_loader"]["key"])
    zarr_dataset = ChunkedDataset(dataset_path)
    zarr_dataset.open()

    raster_cfg = cfg["raster_params"]
    semantic_map_filepath = dm.require(raster_cfg["semantic_map_key"])
    try:
        dataset_meta = _load_metadata(raster_cfg["dataset_meta_key"], dm)
        world_to_ecef = np.array(dataset_meta["world_to_ecef"],
                                 dtype=np.float64)
    except (KeyError, FileNotFoundError):
        world_to_ecef = get_hardcoded_world_to_ecef()

    rast = OpenGLSemanticRasterizer(
        raster_size=raster_cfg["raster_size"],
        pixel_size=raster_cfg["pixel_size"],
        ego_center=raster_cfg["ego_center"],
        filter_agents_threshold=0.5,
        history_num_frames=0,
        semantic_map_path=semantic_map_filepath,
        world_to_ecef=world_to_ecef,
    )
    dataset = AgentDataset(cfg, zarr_dataset, rast)
Esempio n. 6
0
    im = dataset.rasterizer.to_rgb(im)
    target_positions_pixels = transform_points(data["target_positions"] + data["centroid"][:2], data["world_to_image"])
    center_in_pixels = np.asarray(cfg["raster_params"]["ego_center"]) * cfg["raster_params"]["raster_size"]
    draw_trajectory(im, target_positions_pixels, data["target_yaws"], TARGET_POINTS_COLOR)
    clear_output(wait=True)
    display(PIL.Image.fromarray(im[::-1]))

# %% [markdown]
# We can also take a general view of the street from a matplotlib-type perspective. I borrow this from [this wonderful notebook](https://www.kaggle.com/t3nyks/lyft-working-with-map-api)

# %% [code] {"_kg_hide-input":true}
from l5kit.data.map_api import MapAPI
from l5kit.rasterization.rasterizer_builder import _load_metadata

semantic_map_filepath = dm.require(cfg["raster_params"]["semantic_map_key"])
dataset_meta = _load_metadata(cfg["raster_params"]["dataset_meta_key"], dm)
world_to_ecef = np.array(dataset_meta["world_to_ecef"], dtype=np.float64)

map_api = MapAPI(semantic_map_filepath, world_to_ecef)
MAP_LAYERS = ["junction", "node", "segment", "lane"]


def element_of_type(elem, layer_name):
    return elem.element.HasField(layer_name)


def get_elements_from_layer(map_api, layer_name):
    return [elem for elem in map_api.elements if element_of_type(elem, layer_name)]


class MapRenderer: