### Import Argoverse 2.0 API and plotting libraries Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Imports core Argoverse 2.0 API components, plotting utilities, and data loading classes. Ensure matplotlib and numpy are installed. ```python import argparse from pathlib import Path from typing import List import matplotlib import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axes_grid1 import make_axes_locatable import av2.geometry.polyline_utils as polyline_utils import av2.rendering.vector as vector_plotting_utils from av2.datasets.sensor.av2_sensor_dataloader import AV2SensorDataLoader from av2.map.map_api import ArgoverseStaticMap, LaneSegment ``` -------------------------------- ### Load and Use PinholeCamera Source: https://context7.com/argoverse/av2-api/llms.txt Loads a PinholeCamera from a feather file and demonstrates accessing its properties and projecting 3D points to image coordinates. Ensure the log directory and camera name are correct. ```python from pathlib import Path import numpy as np from av2.geometry.camera.pinhole_camera import PinholeCamera, Intrinsics from av2.geometry.se3 import SE3 # Load camera from feather file log_dir = Path("/path/to/log") cam_name = "ring_front_center" camera = PinholeCamera.from_feather(log_dir, cam_name) # Access camera properties print(f"Camera: {camera.cam_name}") print(f"Image size: {camera.width_px} x {camera.height_px}") print(f"Intrinsics matrix K:\n{camera.intrinsics.K}") print(f"Extrinsics (4x4):\n{camera.extrinsics}") # Project 3D points in ego frame to image points_ego = np.array([ [10.0, 0.0, 0.0], # Directly ahead [15.0, 5.0, 1.0], # Right side [20.0, -3.0, 0.5], # Left side ]) uv, points_cam, is_valid = camera.project_ego_to_img(points_ego) print(f"Image coordinates (u, v):\n{uv}") print(f"Valid projections: {is_valid}") ``` -------------------------------- ### Create and Use Cuboid Annotations Source: https://context7.com/argoverse/av2-api/llms.txt Create a Cuboid object from its parameters, access its properties, and perform transformations. Load annotations from a feather file. ```python import numpy as np from pathlib import Path from av2.structures.cuboid import Cuboid, CuboidList from av2.geometry.se3 import SE3 # Create a cuboid from parameters rotation = np.eye(3) translation = np.array([5.0, 2.0, 1.0]) ego_SE3_object = SE3(rotation=rotation, translation=translation) cuboid = Cuboid( dst_SE3_object=ego_SE3_object, length_m=4.5, # x-axis extent width_m=2.0, # y-axis extent height_m=1.5, # z-axis extent category="REGULAR_VEHICLE", timestamp_ns=1234567890 ) # Access cuboid properties print(f"Center: {cuboid.xyz_center_m}") print(f"Dimensions (L,W,H): {cuboid.dims_lwh_m}") print(f"Category: {cuboid.category}") # Get the 8 corner vertices of the cuboid vertices = cuboid.vertices_m # Shape: (8, 3) print(f"Vertices shape: {vertices.shape}") # Check which points are inside the cuboid query_points = np.random.randn(1000, 3) + translation interior_points, is_interior = cuboid.compute_interior_points(query_points) print(f"Points inside cuboid: {is_interior.sum()}") # Transform cuboid to a different reference frame city_SE3_ego = SE3(rotation=np.eye(3), translation=np.array([100, 200, 0])) cuboid_city = cuboid.transform(city_SE3_ego) print(f"Cuboid center in city: {cuboid_city.xyz_center_m}") # Load annotations from feather file annotations_path = Path("/path/to/log/annotations.feather") cuboid_list = CuboidList.from_feather(annotations_path) print(f"Loaded {len(cuboid_list)} cuboids") # Access all centers and dimensions as arrays centers = cuboid_list.xyz_center_m # Shape: (N, 3) dimensions = cuboid_list.dims_lwh_m # Shape: (N, 3) categories = cuboid_list.categories # List of strings ``` -------------------------------- ### Construct detection configuration Source: https://github.com/argoverse/av2-api/blob/main/tutorials/object_detection_evaluation.ipynb Initializes the DetectionCfg object with the dataset directory. This configuration is used for evaluation and defaults to competition parameters. It includes logic to remove cuboids outside the region-of-interest. ```python dataset_dir = ( Path.home() / "data" / "datasets" / "av2" / "sensor" ) # Path to your AV2 sensor dataset directory. competition_cfg = DetectionCfg( dataset_dir=dataset_dir ) # Defaults to competition parameters. ``` -------------------------------- ### Load Sensor Data with AV2SensorDataLoader Source: https://context7.com/argoverse/av2-api/llms.txt Retrieves LiDAR sweeps, camera images, ego poses, and annotations from AV2 sensor logs. Requires valid paths to the dataset directories. ```python from pathlib import Path from av2.datasets.sensor.av2_sensor_dataloader import AV2SensorDataLoader from av2.structures.sweep import Sweep from av2.structures.cuboid import CuboidList # Initialize the dataloader data_dir = Path("/path/to/av2/sensor/val") labels_dir = Path("/path/to/av2/sensor/val") loader = AV2SensorDataLoader(data_dir=data_dir, labels_dir=labels_dir) # Get all available log IDs log_ids = loader.get_log_ids() print(f"Found {len(log_ids)} logs") # Get timestamps for a specific log log_id = log_ids[0] timestamps = loader.get_ordered_log_lidar_timestamps(log_id) print(f"Log {log_id} has {len(timestamps)} LiDAR sweeps") # Load a LiDAR sweep lidar_fpath = loader.get_lidar_fpath(log_id, timestamps[0]) sweep = Sweep.from_feather(lidar_fpath) print(f"Sweep has {len(sweep)} points, shape: {sweep.xyz.shape}") # Get ego pose in city coordinates city_SE3_ego = loader.get_city_SE3_ego(log_id, timestamps[0]) points_city = city_SE3_ego.transform_point_cloud(sweep.xyz) # Load annotations at a timestamp cuboids = loader.get_labels_at_lidar_timestamp(log_id, timestamps[0]) print(f"Found {len(cuboids)} annotations") for cuboid in cuboids.cuboids: print(f" {cuboid.category}: {cuboid.dims_lwh_m}") # Get synchronized camera image cam_name = "ring_front_center" img_fpath = loader.get_closest_img_fpath(log_id, cam_name, timestamps[0]) print(f"Camera image: {img_fpath}") # Get city name for the log city_name = loader.get_city_name(log_id) print(f"City: {city_name}") ``` -------------------------------- ### PinholeCamera Frustum and Ray Utilities Source: https://context7.com/argoverse/av2-api/llms.txt Demonstrates culling points to the camera's view frustum, obtaining frustum planes, and computing pixel ray directions. The `cull_to_view_frustum` method requires image coordinates and corresponding 3D points. ```python # Cull points to camera view frustum is_in_frustum = camera.cull_to_view_frustum(uv, points_cam) # Get camera frustum planes for rendering frustum_planes = camera.frustum_planes(near_clip_dist=0.5) # Shape: (5, 4) # Get camera yaw in ego frame yaw_rad = camera.egovehicle_yaw_cam_rad print(f"Camera yaw: {np.degrees(yaw_rad):.1f} degrees") # Scale camera intrinsics (for multi-resolution processing) camera_half = camera.scale(0.5) print(f"Scaled image size: {camera_half.width_px} x {camera_half.height_px}") # Compute pixel ray directions pixel_coords = np.array([[960, 600], [480, 300]]) # (u, v) coordinates ray_dirs = camera.compute_pixel_ray_directions(pixel_coords) # (N, 3) ``` -------------------------------- ### Create Namespace object for arguments Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Constructs a Namespace object to hold data root and log ID, converting them to Path objects. ```python args = Namespace(**{"dataroot": Path(dataroot), "log_id": Path(log_id)}) ``` -------------------------------- ### Visualize Sensor Dataset Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Visualizes ego-vehicle poses and local vector maps for sensor datasets. ```python def argoverse2_sensor_dataset_teaser( args: argparse.Namespace, save_plot: bool = False ) -> None: """Visualize both ego-vehicle poses and the per-log local vector map. Crosswalks are plotted in purple. Lane segments plotted in dark gray. Ego-pose in red. """ loader = AV2SensorDataLoader(data_dir=args.dataroot, labels_dir=args.dataroot) fig = plt.figure(1, figsize=(10, 10)) ``` -------------------------------- ### Write Video to Disk Source: https://context7.com/argoverse/av2-api/llms.txt Creates a video file from a NumPy array of RGB frames. Specify the output path, color format, frames per second, and quality settings. The `crf` parameter controls quality (lower is better quality, larger file size). ```python import numpy as np from pathlib import Path from av2.rendering.video import write_video from av2.rendering.color import ColorFormats # Create a video from RGB frames num_frames = 100 height, width = 480, 640 video_frames = np.random.randint(0, 255, (num_frames, height, width, 3), dtype=np.uint8) # Write video to disk output_path = Path("/tmp/output_video.mp4") write_video( video=video_frames, dst=output_path, color_format=ColorFormats.RGB, fps=10, crf=23, # Quality (lower = better quality, larger file) preset="fast", ) print(f"Video saved to: {output_path}") ``` -------------------------------- ### Render Single Log Teaser Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Renders a bird's eye view of local crosswalks and pedestrian crossings for a single log. ```python def single_log_teaser(args: argparse.Namespace) -> None: """For a single log, render all local crosswalks in green, and pedestrian crossings in purple, in a bird's eye view.""" log_map_dirpath = Path(args.dataroot) / args.log_id / "map" avm = ArgoverseStaticMap.from_map_dir(log_map_dirpath, build_raster=False) fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot() for _, ls in avm.vector_lane_segments.items(): # right_ln_bnd # left_ln_bnd vector_plotting_utils.draw_polygon_mpl( ax, ls.polygon_boundary, color="g", linewidth=0.5 ) vector_plotting_utils.plot_polygon_patch_mpl( ls.polygon_boundary, ax, color="g", alpha=0.2 ) # plot all pedestrian crossings for _, pc in avm.vector_pedestrian_crossings.items(): vector_plotting_utils.draw_polygon_mpl(ax, pc.polygon, color="m", linewidth=0.5) vector_plotting_utils.plot_polygon_patch_mpl( pc.polygon, ax, color="m", alpha=0.2 ) plt.show() ``` ```python single_log_teaser(args) ``` -------------------------------- ### Serialize Motion Forecasting Scenarios Source: https://context7.com/argoverse/av2-api/llms.txt Load and save motion forecasting scenarios using parquet files. Provides access to track metadata and object states. ```python from pathlib import Path from av2.datasets.motion_forecasting.scenario_serialization import ( load_argoverse_scenario_parquet, serialize_argoverse_scenario_parquet, ) from av2.datasets.motion_forecasting.data_schema import ( ArgoverseScenario, Track, ObjectState, ObjectType, TrackCategory, ) # Load a scenario from parquet file scenario_path = Path("/path/to/scenario/scenario_uuid.parquet") scenario = load_argoverse_scenario_parquet(scenario_path) # Access scenario metadata print(f"Scenario ID: {scenario.scenario_id}") print(f"City: {scenario.city_name}") print(f"Focal track ID: {scenario.focal_track_id}") print(f"Number of timestamps: {len(scenario.timestamps_ns)}") print(f"Number of tracks: {len(scenario.tracks)}") # Iterate over tracks for track in scenario.tracks: print(f"\nTrack {track.track_id}:") print(f" Type: {track.object_type.value}") print(f" Category: {track.category.name}") print(f" States: {len(track.object_states)}") # Access individual states for state in track.object_states[:3]: print(f" Timestep {state.timestep}: pos={state.position}, " f"heading={state.heading:.2f}, vel={state.velocity}") # Find the focal track focal_track = next(t for t in scenario.tracks if t.track_id == scenario.focal_track_id) print(f"\nFocal track type: {focal_track.object_type.value}") # Get observed vs predicted timesteps observed_states = [s for s in focal_track.object_states if s.observed] future_states = [s for s in focal_track.object_states if not s.observed] print(f"Observed: {len(observed_states)}, Future: {len(future_states)}") # Save a scenario output_path = Path("/path/to/output/scenario.parquet") serialize_argoverse_scenario_parquet(output_path, scenario) ``` -------------------------------- ### Import necessary libraries for evaluation Source: https://github.com/argoverse/av2-api/blob/main/tutorials/object_detection_evaluation.ipynb Imports the required modules for 3D object detection evaluation and configuration. ```python from av2.evaluation.detection.eval import evaluate from av2.evaluation.detection.utils import DetectionCfg from pathlib import Path from av2.utils.io import read_feather, read_all_annotations ``` -------------------------------- ### Load and evaluate detections Source: https://github.com/argoverse/av2-api/blob/main/tutorials/object_detection_evaluation.ipynb Loads detection data from a feather file and then evaluates it against the ground truth annotations using the competition configuration. The function returns the evaluated detections, ground truths, and computed metrics. ```python # If you've already aggregated your detections into one file. dts_path = Path("detections.feather") dts = read_feather(dts_path) dts, gts, metrics = evaluate(dts, gts, cfg=competition_cfg) # Evaluate instances. ``` -------------------------------- ### Load Detection Data with PyTorch Source: https://context7.com/argoverse/av2-api/llms.txt Utilizes the DetectionDataLoader for high-performance 3D object detection tasks. Supports point cloud accumulation and integration with Kornia for coordinate transformations. ```python from pathlib import Path from av2.torch.data_loaders.detection import DetectionDataLoader from kornia.geometry.linalg import transform_points from tqdm import tqdm # Initialize the PyTorch data loader root_dir = Path.home() / "data" / "datasets" data_loader = DetectionDataLoader( root_dir=root_dir, dataset_name="av2", split_name="val", num_accumulated_sweeps=1, # Accumulate multiple sweeps for denser point clouds memory_mapped=False ) print(f"Dataset has {len(data_loader)} sweeps") # Iterate over the dataset for i, sweep in enumerate(tqdm(data_loader)): # Get the SE(3) transformation matrix (4x4) city_SE3_ego_mat4 = sweep.city_SE3_ego.matrix() # Get LiDAR tensor (x, y, z, intensity) lidar_tensor = sweep.lidar.as_tensor() print(f"LiDAR shape: {lidar_tensor.shape}") # (N, 4) # Transform points to city coordinates using kornia lidar_xyz_city = transform_points(city_SE3_ego_mat4, lidar_tensor[:, :3]) # Get synchronized ring camera images synchronized_images = data_loader.get_synchronized_images(i) print(f"Number of camera images: {len(synchronized_images)}") # Access cuboid annotations (if available) if sweep.cuboids is not None: # Get cuboid parameters (x, y, z, length, width, height, yaw) xyzlwh_t = sweep.cuboids.as_tensor() categories = sweep.cuboids.category track_uuids = sweep.cuboids.track_uuid print(f"Found {len(categories)} cuboids") if i >= 5: break ``` -------------------------------- ### Visualize Motion Forecasting Scenario Source: https://context7.com/argoverse/av2-api/llms.txt Generates a video visualization for a motion forecasting scenario, combining track trajectories with HD map data. This function requires scenario data and a static map object. Ensure paths to scenario and map files are correct. ```python from pathlib import Path from av2.datasets.motion_forecasting import scenario_serialization from av2.datasets.motion_forecasting.viz.scenario_visualization import visualize_scenario from av2.map.map_api import ArgoverseStaticMap # Load scenario and map scenario_dir = Path("/path/to/motion_forecasting/val") scenario_files = list(scenario_dir.rglob("*.parquet")) for scenario_path in scenario_files[:5]: # Extract scenario ID and load data scenario_id = scenario_path.stem.split("_")[-1] map_path = scenario_path.parent / f"log_map_archive_{scenario_id}.json" scenario = scenario_serialization.load_argoverse_scenario_parquet(scenario_path) static_map = ArgoverseStaticMap.from_json(map_path) # Generate visualization video output_path = Path(f"/tmp/viz_{scenario_id}.mp4") visualize_scenario(scenario, static_map, output_path) print(f"Generated visualization: {output_path}") ``` -------------------------------- ### Tile Multiple Camera Images Source: https://context7.com/argoverse/av2-api/llms.txt Combines images from multiple cameras into a single tiled visualization. The input is a dictionary where keys are camera names and values are NumPy arrays representing the images. ```python from av2.rendering.video import tile_cameras # Tile multiple camera images into a single frame # Simulated camera images (landscape format) camera_images = { "ring_front_left": np.random.randint(0, 255, (1550, 2048, 3), dtype=np.uint8), "ring_front_center": np.random.randint(0, 255, (2048, 1550, 3), dtype=np.uint8), "ring_front_right": np.random.randint(0, 255, (1550, 2048, 3), dtype=np.uint8), "ring_side_left": np.random.randint(0, 255, (1550, 2048, 3), dtype=np.uint8), "ring_side_right": np.random.randint(0, 255, (1550, 2048, 3), dtype=np.uint8), "ring_rear_left": np.random.randint(0, 255, (1550, 2048, 3), dtype=np.uint8), "ring_rear_right": np.random.randint(0, 255, (1550, 2048, 3), dtype=np.uint8), } # Create tiled visualization tiled_image = tile_cameras(camera_images) print(f"Tiled image shape: {tiled_image.shape}") ``` -------------------------------- ### Import necessary modules Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Imports required modules for argument parsing and path manipulation. ```python from argparse import Namespace from pathlib import Path ``` -------------------------------- ### Load LiDAR Sweep Data Source: https://context7.com/argoverse/av2-api/llms.txt Load a LiDAR sweep from a feather file and access its point cloud data and sensor poses. The sweep data is egomotion compensated to the reference timestamp. ```python from pathlib import Path from av2.structures.sweep import Sweep # Load a sweep from feather file sweep_path = Path("/path/to/log/sensors/lidar/315968193359876000.feather") sweep = Sweep.from_feather(sweep_path) # Access point cloud data xyz = sweep.xyz # (N, 3) float array - x, y, z in meters intensity = sweep.intensity # (N,) uint8 array - intensity values [0-255] laser_number = sweep.laser_number # (N,) uint8 array - laser beam indices [0-63] offset_ns = sweep.offset_ns # (N,) int array - nanosecond offsets from sweep start print(f"Number of points: {len(sweep)}") print(f"Point cloud shape: {xyz.shape}") print(f"Timestamp: {sweep.timestamp_ns} ns") # Access sensor poses in ego frame ego_SE3_up_lidar = sweep.ego_SE3_up_lidar ego_SE3_down_lidar = sweep.ego_SE3_down_lidar print(f"Up lidar position: {ego_SE3_up_lidar.translation}") ``` -------------------------------- ### Compute Motion Forecasting Metrics Source: https://context7.com/argoverse/av2-api/llms.txt Calculate evaluation metrics like ADE and FDE for forecasted trajectories. Requires ground truth and predicted trajectory arrays. ```python import numpy as np from av2.datasets.motion_forecasting.eval.metrics import ( compute_ade, compute_fde, compute_is_missed_prediction, compute_brier_ade, compute_brier_fde, ) # Ground truth trajectory (N timesteps, 2D coordinates) gt_trajectory = np.array([ [0.0, 0.0], [1.0, 0.5], [2.0, 1.0], [3.0, 1.5], [4.0, 2.0], ]) # Shape: (N, 2) # K predicted trajectories K = 6 # Number of predictions N = 5 # Number of timesteps forecasted_trajectories = np.random.randn(K, N, 2) + gt_trajectory # Shape: (K, N, 2) # Compute Average Displacement Error for each prediction ade = compute_ade(forecasted_trajectories, gt_trajectory) print(f"ADE for each prediction: {ade}") # Shape: (K,) print(f"Best ADE (minADE): {ade.min():.3f}") # Compute Final Displacement Error for each prediction fde = compute_fde(forecasted_trajectories, gt_trajectory) print(f"FDE for each prediction: {fde}") # Shape: (K,) print(f"Best FDE (minFDE): {fde.min():.3f}") ``` -------------------------------- ### Load Argoverse Static Map Source: https://context7.com/argoverse/av2-api/llms.txt Load the Argoverse static map data from a JSON file or a directory containing raster data. Access scenario lane segments. ```python from pathlib import Path import numpy as np from av2.map.map_api import ArgoverseStaticMap # Load map from JSON file map_path = Path("/path/to/log/map/log_map_archive_uuid.json") static_map = ArgoverseStaticMap.from_json(map_path) # Or load from directory with raster data map_dir = Path("/path/to/log/map") static_map = ArgoverseStaticMap.from_map_dir(map_dir, build_raster=True) # Get all lane segments lane_segments = static_map.get_scenario_lane_segments() print(f"Number of lane segments: {len(lane_segments)}") ``` -------------------------------- ### Compute Motion Forecasting Metrics Source: https://context7.com/argoverse/av2-api/llms.txt Calculate prediction miss rates and probability-weighted metrics like Brier scores for forecasted trajectories. ```python miss_threshold = 2.0 # meters is_missed = compute_is_missed_prediction( forecasted_trajectories, gt_trajectory, miss_threshold_m=miss_threshold ) miss_rate = is_missed.mean() print(f"Miss rate (threshold={miss_threshold}m): {miss_rate:.2%}") # Compute probability-weighted metrics (Brier score) forecast_probabilities = np.array([0.3, 0.25, 0.2, 0.15, 0.07, 0.03]) # Sum to 1 brier_ade = compute_brier_ade( forecasted_trajectories, gt_trajectory, forecast_probabilities, normalize=True ) brier_fde = compute_brier_fde( forecasted_trajectories, gt_trajectory, forecast_probabilities, normalize=True ) print(f"Brier-weighted ADE: {brier_ade.min():.3f}") print(f"Brier-weighted FDE: {brier_fde.min():.3f}") ``` -------------------------------- ### Visualize Raster Layers Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Visualizes ground surface height and side-by-side plots of raster arrays. ```python def visualize_raster_layers(args: argparse.Namespace) -> None: """Visualize the ground surface height/elevation map, w/ a colorbar indicating the value range. Also, visualize side-by-side plots of the 3 raster arrays -- ground height, drivable area, ROI. """ log_map_dirpath = Path(args.dataroot) / args.log_id / "map" avm = ArgoverseStaticMap.from_map_dir(log_map_dirpath, build_raster=True) height_array = avm.raster_ground_height_layer.array ax = plt.subplot() plt.title("Ground surface height (@ 30 centimeter resolution).") img = plt.imshow(np.flipud(height_array)) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) plt.colorbar(img, cax=cax) plt.show() plt.figure(figsize=(20, 10)) plt.subplot(1, 3, 1) plt.imshow(np.flipud(height_array)) plt.title("Ground Surface Height") plt.subplot(1, 3, 2) da_array = avm.raster_drivable_area_layer.array plt.imshow(np.flipud(da_array)) plt.title("Drivable Area (rasterized \nfrom vector polygons)") plt.subplot(1, 3, 3) roi_array = avm.raster_roi_layer.array plt.imshow(np.flipud(roi_array)) plt.title("Region of Interest (ROI)") plt.show() ``` ```python visualize_raster_layers(args) ``` -------------------------------- ### Evaluate 3D Object Detection Source: https://context7.com/argoverse/av2-api/llms.txt Configure and run detection evaluation using pandas DataFrames for detections and ground truth data. ```python import pandas as pd import numpy as np from pathlib import Path from av2.evaluation.detection.eval import evaluate from av2.evaluation.detection.utils import DetectionCfg # Prepare detection DataFrame # Columns: log_id, timestamp_ns, category, tx_m, ty_m, tz_m, length_m, width_m, height_m, qw, qx, qy, qz, score detections = pd.DataFrame({ "log_id": ["log_001"] * 3, "timestamp_ns": [1234567890] * 3, "category": ["REGULAR_VEHICLE", "PEDESTRIAN", "REGULAR_VEHICLE"], "tx_m": [10.0, 15.0, 20.0], "ty_m": [5.0, 8.0, 3.0], "tz_m": [1.0, 1.0, 1.0], "length_m": [4.5, 0.8, 4.2], "width_m": [2.0, 0.6, 1.9], "height_m": [1.5, 1.7, 1.6], "qw": [1.0, 1.0, 0.707], "qx": [0.0, 0.0, 0.0], "qy": [0.0, 0.0, 0.0], "qz": [0.0, 0.0, 0.707], "score": [0.95, 0.88, 0.75], }) # Prepare ground truth DataFrame # Columns: log_id, timestamp_ns, category, tx_m, ty_m, tz_m, length_m, width_m, height_m, qw, qx, qy, qz, num_interior_pts ground_truth = pd.DataFrame({ "log_id": ["log_001"] * 2, "timestamp_ns": [1234567890] * 2, "category": ["REGULAR_VEHICLE", "PEDESTRIAN"], "tx_m": [10.1, 15.2], "ty_m": [5.1, 7.9], "tz_m": [1.0, 1.0], "length_m": [4.5, 0.8], "width_m": [2.0, 0.6], "height_m": [1.5, 1.7], "qw": [1.0, 1.0], "qx": [0.0, 0.0], "qy": [0.0, 0.0], "qz": [0.0, 0.0], "num_interior_pts": [100, 50], }) # Configure evaluation cfg = DetectionCfg( categories=["REGULAR_VEHICLE", "PEDESTRIAN"], eval_only_roi_instances=False, # Set True to filter by ROI # dataset_dir=Path("/path/to/dataset"), # Required if eval_only_roi_instances=True ) # Run evaluation dts_results, gts_results, metrics = evaluate( dts=detections, gts=ground_truth, cfg=cfg, n_jobs=4, ) # Display metrics print("\nDetection Metrics:") print(metrics) # Metrics include: AP (Average Precision), ATE (Translation Error), # ASE (Scale Error), AOE (Orientation Error), CDS (Composite Detection Score) ``` -------------------------------- ### Display evaluation metrics Source: https://github.com/argoverse/av2-api/blob/main/tutorials/object_detection_evaluation.ipynb Displays the computed evaluation metrics after running the detection evaluation. ```python display(metrics) ``` -------------------------------- ### Call Argoverse2 Sensor Dataset Teaser Function Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb This is a function call to initiate the Argoverse2 sensor dataset teaser. It likely triggers a series of visualizations or data processing steps. ```python argoverse2_sensor_dataset_teaser(args) ``` -------------------------------- ### Load ground truth annotations Source: https://github.com/argoverse/av2-api/blob/main/tutorials/object_detection_evaluation.ipynb Reads all ground truth annotations for a specified split (e.g., 'val') from the dataset directory. The annotations are returned as a pandas DataFrame. ```python split = "val" gts = read_all_annotations( dataset_dir=dataset_dir, split=split ) # Contains all annotations in a particular split. display(gts) ``` -------------------------------- ### Evaluate Scene Flow Source: https://context7.com/argoverse/av2-api/llms.txt Compute point-wise metrics for 3D motion estimation, including end-point error and accuracy thresholds. ```python import numpy as np from pathlib import Path from av2.evaluation.scene_flow.eval import ( compute_end_point_error, compute_accuracy_strict, compute_accuracy_relax, compute_angle_error, evaluate_directories, results_to_dict, ) # Compute point-wise end-point error predicted_flow = np.array([ [0.1, 0.2, 0.05], [0.5, -0.1, 0.02], [1.0, 0.0, 0.0], ]) # Shape: (N, 3) ground_truth_flow = np.array([ [0.12, 0.18, 0.04], [0.48, -0.12, 0.03], [1.1, 0.05, 0.0], ]) # Shape: (N, 3) # End-Point Error (EPE) epe = compute_end_point_error(predicted_flow, ground_truth_flow) print(f"End-Point Error: {epe}") # Shape: (N,) print(f"Mean EPE: {epe.mean():.4f} meters") # Accuracy with strict threshold (0.05) acc_strict = compute_accuracy_strict(predicted_flow, ground_truth_flow) print(f"Strict Accuracy: {acc_strict.mean():.2%}") # Accuracy with relaxed threshold (0.1) acc_relax = compute_accuracy_relax(predicted_flow, ground_truth_flow) print(f"Relaxed Accuracy: {acc_relax.mean():.2%}") # Angle error in space-time angle_err = compute_angle_error(predicted_flow, ground_truth_flow) print(f"Angle Error: {np.degrees(angle_err).mean():.2f} degrees") # Evaluate from directories (for challenge submissions) annotations_dir = Path("/path/to/annotations") predictions_dir = Path("/path/to/predictions") # results_df = evaluate_directories(annotations_dir, predictions_dir) # results_dict = results_to_dict(results_df) # # print("\nScene Flow Results:") # for metric, value in results_dict.items(): # print(f" {metric}: {value:.4f}") ``` -------------------------------- ### Plot Argoverse Log Data with Matplotlib Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Visualizes ego-vehicle trajectory and map elements from an Argoverse log. Ensure necessary imports and data loading functions are available. ```python ax = fig.add_subplot(111) log_map_dirpath = Path(args.dataroot) / args.log_id / "map" avm = ArgoverseStaticMap.from_map_dir(log_map_dirpath, build_raster=False) # retain every pose first. traj_ns = loader.get_subsampled_ego_trajectory(args.log_id, sample_rate_hz=1e9) # now, sample @ 1 Hz traj_1hz = loader.get_subsampled_ego_trajectory(args.log_id, sample_rate_hz=1.0) med_x, med_y = np.median(traj_ns, axis=0) # Derive plot area from trajectory (with radius defined in infinity norm). view_radius_m = 50 xlims = [med_x - view_radius_m, med_x + view_radius_m] ylims = [med_y - view_radius_m, med_y + view_radius_m] crosswalk_color = PURPLE_RGB_MPL CROSSWALK_ALPHA = 0.6 for pc in avm.get_scenario_ped_crossings(): vector_plotting_utils.plot_polygon_patch_mpl( polygon_pts=pc.polygon[:, :2], ax=ax, color=crosswalk_color, alpha=CROSSWALK_ALPHA, zorder=3, ) plot_lane_segments(ax=ax, lane_segments=avm.get_scenario_lane_segments()) ax.plot(traj_ns[:, 0], traj_ns[:, 1], color="r", zorder=4, label="Ego-vehicle pose") ax.scatter( traj_1hz[:, 0], traj_1hz[:, 1], 100, facecolors="none", edgecolors="r", zorder=4 ) # marker='o', color="r") plt.axis("equal") plt.xlim(*xlims) plt.ylim(*ylims) plt.title(f"Log {args.log_id}") plt.axis("off") plt.legend() plt.tight_layout() plt.show() ``` -------------------------------- ### Transform Point Cloud Source: https://context7.com/argoverse/av2-api/llms.txt Transform a point cloud using a given transformation matrix. Ensure the input points are in the correct shape (N, 3). ```python import numpy as np from av2.geometry.se3 import SE3 # Assuming 'transform' is an SE3 object # Access the 4x4 homogeneous transformation matrix transform_matrix = transform.transform_matrix print(f"Transform matrix shape: {transform_matrix.shape}") # (4, 4) # Transform a point cloud points = np.random.randn(1000, 3) # N x 3 point cloud transformed_points = transform.transform_point_cloud(points) # Equivalent: transformed_points = transform.transform_from(points) # Compute the inverse transformation inverse_transform = transform.inverse() original_points = inverse_transform.transform_point_cloud(transformed_points) np.testing.assert_allclose(points, original_points, atol=1e-10) # Compose two transformations: result = T1 * T2 T1 = SE3(rotation=np.eye(3), translation=np.array([1, 0, 0])) T2 = SE3(rotation=np.eye(3), translation=np.array([0, 1, 0])) T_composed = T1.compose(T2) print(f"Composed translation: {T_composed.translation}") # [1, 1, 0] ``` -------------------------------- ### Export detections to feather file Source: https://github.com/argoverse/av2-api/blob/main/tutorials/object_detection_evaluation.ipynb Exports the processed detections DataFrame to a feather file named 'detections.feather'. This format is suitable for submission to the evaluation server. ```python dts.to_feather("detections.feather") ``` -------------------------------- ### PinholeCamera Motion Compensation Projection Source: https://context7.com/argoverse/av2-api/llms.txt Projects 3D points to image coordinates with motion compensation, aligning LiDAR data to camera timestamps. Requires SE3 objects for camera and LiDAR poses at a given time. ```python city_SE3_ego_cam_t = SE3(rotation=np.eye(3), translation=np.array([100, 200, 0])) city_SE3_ego_lidar_t = SE3(rotation=np.eye(3), translation=np.array([100.1, 200.05, 0])) uv_compensated, points_cam_compensated, is_valid_compensated = ( camera.project_ego_to_img_motion_compensated( points_lidar_time=points_ego, city_SE3_ego_cam_t=city_SE3_ego_cam_t, city_SE3_ego_lidar_t=city_SE3_ego_lidar_t, ) ) ``` -------------------------------- ### Define data root and log ID Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Specifies the root directory for Argoverse 2.0 data and a unique log identifier. ```python # path to where the logs live dataroot = "/Users/jlambert/Downloads/av2-v7-2022-01-15" # unique log identifier log_id = "adcf7d18-0510-35b0-a2fa-b4cea13a6d76" ``` -------------------------------- ### Perform SE3 Rigid Transformations Source: https://context7.com/argoverse/av2-api/llms.txt Defines rigid body transformations in 3D space using the SE3 class. Requires rotation and translation components. ```python import numpy as np from av2.geometry.se3 import SE3 # Create an SE3 transformation rotation = np.array([ [1, 0, 0], [0, np.cos(np.pi/4), -np.sin(np.pi/4)], [0, np.sin(np.pi/4), np.cos(np.pi/4)] ]) translation = np.array([10.0, 5.0, 2.0]) transform = SE3(rotation=rotation, translation=translation) ``` -------------------------------- ### Define RGB Color Constants Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Define color constants scaled for matplotlib usage. ```python # scaled to [0,1] for matplotlib. PURPLE_RGB = [201, 71, 245] PURPLE_RGB_MPL = np.array(PURPLE_RGB) / 255 DARK_GRAY_RGB = [40, 39, 38] DARK_GRAY_RGB_MPL = np.array(DARK_GRAY_RGB) / 255 ``` -------------------------------- ### Plot Lane Segments Source: https://github.com/argoverse/av2-api/blob/main/tutorials/map_tutorial.ipynb Plots lane segments with specific boundary types and styling. ```python def plot_lane_segments( ax: matplotlib.axes.Axes, lane_segments: List[LaneSegment], lane_color: np.ndarray = DARK_GRAY_RGB_MPL, ) -> None: """Plot lane segments.""" for ls in lane_segments: pts_city = ls.polygon_boundary ALPHA = 1.0 # 0.1 vector_plotting_utils.plot_polygon_patch_mpl( polygon_pts=pts_city, ax=ax, color=lane_color, alpha=ALPHA, zorder=1 ) for bound_type, bound_city in zip( [ls.left_mark_type, ls.right_mark_type], [ls.left_lane_boundary, ls.right_lane_boundary], ): if "YELLOW" in bound_type: mark_color = "y" elif "WHITE" in bound_type: mark_color = "w" else: mark_color = "grey" # "b" lane_color # LOOSELY_DASHED = (0, (5, 10)) if "DASHED" in bound_type: linestyle = LOOSELY_DASHED else: linestyle = "solid" if "DOUBLE" in bound_type: left, right = polyline_utils.get_double_polylines( polyline=bound_city.xyz[:, :2], width_scaling_factor=0.1 ) ax.plot( left[:, 0], left[:, 1], mark_color, alpha=ALPHA, linestyle=linestyle, zorder=2, ) ax.plot( right[:, 0], right[:, 1], mark_color, alpha=ALPHA, linestyle=linestyle, zorder=2, ) else: ax.plot( bound_city.xyz[:, 0], bound_city.xyz[:, 1], mark_color, alpha=ALPHA, linestyle=linestyle, zorder=2, ) ``` -------------------------------- ### Query Static Map Lane Data Source: https://context7.com/argoverse/av2-api/llms.txt Access lane segment properties, centerlines, and drivable areas from a static map. Requires a loaded static map object. ```python lane_ids = static_map.get_scenario_lane_segment_ids() for lane_id in lane_ids[:3]: # Get centerline polyline centerline = static_map.get_lane_segment_centerline(lane_id) print(f"Lane {lane_id} centerline shape: {centerline.shape}") # (N, 3) # Get lane polygon boundary polygon = static_map.get_lane_segment_polygon(lane_id) # Check lane properties is_intersection = static_map.lane_is_in_intersection(lane_id) successors = static_map.get_lane_segment_successor_ids(lane_id) left_neighbor = static_map.get_lane_segment_left_neighbor_id(lane_id) right_neighbor = static_map.get_lane_segment_right_neighbor_id(lane_id) # Get nearby lanes query_point = np.array([100.0, 200.0]) nearby_lanes = static_map.get_nearby_lane_segments(query_point, search_radius_m=50.0) print(f"Found {len(nearby_lanes)} lanes within 50m") # Get drivable areas drivable_areas = static_map.get_scenario_vector_drivable_areas() print(f"Number of drivable area polygons: {len(drivable_areas)}") # Get pedestrian crossings ped_crossings = static_map.get_scenario_ped_crossings() print(f"Number of pedestrian crossings: {len(ped_crossings)}") # Filter points to drivable area (requires build_raster=True) points_xyz = np.random.randn(1000, 3) * 50 drivable_points = static_map.remove_non_drivable_area_points(points_xyz) print(f"Points in drivable area: {len(drivable_points)}/{len(points_xyz)}") # Remove ground surface points non_ground_points = static_map.remove_ground_surface(points_xyz) # Check if points are on ground is_ground = static_map.get_ground_points_boolean(points_xyz) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.