Argoverse av2-api

repository·main·Indexed 19 days ago

https://github.com/argoverse/av2-api

Official Python/Rust API for interacting with Argoverse 2 (AV2) and Trust, but Verify (TbV) autonomous driving datasets. It supports tasks including 3D object detection, motion forecasting, 3D scene flow, 4D occupancy forecasting, end-to-end forecasting, and scenario mining. The library provides tools for loading sensor data via a DataLoader, projecting 3D points using PinholeCamera models, applying geometric augmentations, and exporting accumulated lidar sweeps or augmentation databases.

Tokens
19K
Snippets
85
Records
101
Agent score
64%

What's inside av2-api

  1. Overview of Argoverse 2 (AV2) and Trust, but Verify (TbV) datasets

    main

    The av2-api repository provides the official interface for the Argoverse 2 (AV2) and Trust, but Verify (TbV) families of datasets.

    Argoverse 2 (AV2) Datasets

    • Sensor: Perception-focused sensor data.
    • Lidar: Lidar-specific datasets.
    • Motion Forecasting: Datasets designed for predicting agent motion.

    Trust, but Verify (TbV) Datasets

    • Map Change Detection: Datasets focused on detecting changes in HD maps.

    Supported Tasks for AV2

    • 3D Object Detection
    • 3D Scene Flow
    • 4D Occupancy Forecasting
    • End-to-End Forecasting
    • Motion Forecasting
    • Scenario Mining
  2. Visualize map data with matplotlib

    main

    The Argoverse 2 API provides utility functions for plotting map data using matplotlib and numpy:

    • av2.rendering.vector.draw_polygon_mpl: Draws a polygon boundary.
    • av2.rendering.vector.plot_polygon_patch_mpl: Fills a polygon patch (useful for shaded areas like lanes or crosswalks).
    • av2.geometry.polyline_utils.get_double_polylines: Used to expand a single line into a double line (e.g., for double yellow lines).
  3. Construct the 3D object detection evaluation configuration

    main

    Use the DetectionCfg class to define parameters for the 3D object detection challenge.

    Region of Interest (ROI) Behavior: During evaluation, all cuboids outside the ROI are removed. The ROI is defined as a 5-meter dilation of the drivable area isocontour.

    Local Evaluation Requirement: To enable ROI filtering during local evaluation, you must provide the path to your sensor dataset via the dataset_dir argument. This allows the API to build raster maps from the included vector maps.

    from av2.evaluation.detection.utils import DetectionCfg
    from pathlib import Path
    
    dataset_dir = Path.home() / "data" / "datasets" / "av2" / "sensor"
    competition_cfg = DetectionCfg(dataset_dir=dataset_dir)
  4. Configure SceneFlowDataloader arguments

    main

    When initializing SceneFlowDataloader, use the following arguments:

    ArgumentTypeDefaultDescription
    root_dirPathTypeRequiredPath to the dataset directory.
    dataset_namestrRequiredDataset name (e.g., "av2").
    split_namestrRequiredName of the dataset split (e.g., "train", "val").
    num_accumulated_sweepsint1Number of temporally accumulated sweeps (accounting for ego-vehicle motion).
    memory_mappedboolFalseWhether to memory map the dataframes for faster access.
  5. Configure DetectionDataLoader arguments

    main

    When initializing DetectionDataLoader, use the following parameters:

    ArgumentTypeDefaultDescription
    root_dirPathTypeRequiredPath to the base dataset directory.
    dataset_namestrRequiredName of the dataset (e.g., "av2").
    split_namestrRequiredName of the dataset split (e.g., "train", "val").
    num_accumulated_sweepsint1Number of temporally accumulated sweeps to account for ego-vehicle motion.
    memory_mappedboolFalseWhether to memory map the dataframes for faster access.
  6. Retrieve ego-vehicle trajectory with AV2SensorDataLoader

    main

    Use AV2SensorDataLoader to extract vehicle poses. The get_subsampled_ego_trajectory method allows you to sample the trajectory at a specific frequency.

    • sample_rate_hz=1e9: Returns the full resolution trajectory.
    • sample_rate_hz=1.0: Returns a trajectory sampled at 1 Hz.
    from av2.datasets.sensor.av2_sensor_dataloader import AV2SensorDataLoader
    
    loader = AV2SensorDataLoader(data_dir=args.dataroot, labels_dir=args.dataroot)
    
    # Get full resolution trajectory
    traj_ns = loader.get_subsampled_ego_trajectory(args.log_id, sample_rate_hz=1e9)
    
    # Get 1 Hz sampled trajectory
    traj_1hz = loader.get_subsampled_ego_trajectory(args.log_id, sample_rate_hz=1.0)
  7. Convert Tait-Bryan angles to rotation matrices

    main

    Use xyz_to_mat to convert a sequence of extrinsic Tait-Bryan angles (in radians) into a 3D rotation matrix. This function computes the rotation as $R = R_z(z) imes R_y(y) imes R_x(x)$.

    • xyz_to_mat(xyz_rad): Returns a rotation matrix of shape (..., 3, 3).
    # xyz_rad is a (..., 3) array of angles in radians
    mat = xyz_to_mat(xyz_rad)
  8. Convert quaternions to 3x3 rotation matrices

    main

    Use quat_to_mat3 to convert a batch of quaternions in scalar-first (wxyz) format into 3x3 rotation matrices. This function is parallelized for batch processing.

    Input: ArrayView<f32, Ix2> of shape (N, 4) where each row is [w, x, y, z]. Output: Array<f32, Ix3> of shape (N, 3, 3).

    // Assuming quat_wxyz is an ArrayView<f32, Ix2> of shape (N, 4)
    let mat3_batch = quat_to_mat3(&quat_wxyz);
  9. Serialize and deserialize Sim2 objects

    main

    You can persist Sim2 objects to disk using JSON or instantiate them from 3x3 matrices.

    • save_as_json(save_fpath): Saves the rotation (flattened), translation (flattened), and scale to a JSON file.
    • from_json(json_fpath): Loads a Sim2 object from a JSON file.
    • from_matrix(T): Creates a Sim2 instance from a 3x3 NumPy matrix. The scale is derived from $1 / T[2, 2]$.
    from pathlib import Path
    import numpy as np
    from av2.geometry.sim2 import Sim2
    
    # Save to JSON
    sim.save_as_json(Path("transform.json"))
    
    # Load from JSON
    new_sim = Sim2.from_json(Path("transform.json"))
    
    # Create from a 3x3 matrix
    T = np.array([[1, 0, 5], [0, 1, 5], [0, 0, 0.5]])
    sim_from_mat = Sim2.from_matrix(T)
  10. Load map data using ArgoverseStaticMap

    main

    To access map data for a specific log, use ArgoverseStaticMap.from_map_dir. You must provide the path to the map directory within the log folder.

    • Use build_raster=False to load only vector data (lanes, pedestrian crossings, etc.).
    • Use build_raster=True to also generate raster layers (ground height, drivable area, ROI).
    from pathlib import Path
    from av2.map.map_api import ArgoverseStaticMap
    
    log_map_dirpath = Path(args.dataroot) / args.log_id / "map"
    avm = ArgoverseStaticMap.from_map_dir(log_map_dirpath, build_raster=False)