NuScenes Devkit

1.2.0 · active · verified Thu Apr 16

The NuScenes Devkit is the official Python toolkit for interacting with the NuScenes dataset, a large-scale dataset for autonomous driving. It provides functionalities for loading, processing, visualizing, and evaluating data from the NuScenes and NuImages datasets. The current version is 1.2.0, with a release cadence that includes several minor updates and bug fixes per year, alongside occasional major updates for new dataset releases or features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `NuScenes` object, which is the primary entry point for interacting with the dataset. It highlights the critical `dataroot` and `version` parameters, which must correspond to your locally downloaded and extracted NuScenes data. The code also includes basic error handling for common setup issues.

import os
from nuscenes.nuscenes import NuScenes

# IMPORTANT: Before running, you must download a NuScenes dataset split
# (e.g., v1.0-mini) from www.nuscenes.org and extract it.
# The 'dataroot' should point to the directory containing 'sets/nuscenes'.
# Example directory structure: /your/chosen/root/sets/nuscenes/v1.0-mini

# Replace with the actual path to your NuScenes data root directory
dataroot = os.environ.get('NUSCENES_DATAROOT', '/tmp/nuscenes_data_root')
# Replace with the dataset version you downloaded (e.g., 'v1.0-trainval', 'v1.0-mini')
version = os.environ.get('NUSCENES_VERSION', 'v1.0-mini')

try:
    # Initialize the NuScenes object
    nusc = NuScenes(version=version, dataroot=dataroot, verbose=True)
    print(f"Successfully loaded NuScenes dataset version '{nusc.version}' from '{nusc.dataroot}'")

    # Print some basic statistics
    print(f"Number of scenes: {len(nusc.scene)}")
    print(f"Number of samples: {len(nusc.sample)}")

    # Example: Access the first scene
    first_scene = nusc.scene[0]
    print(f"\nFirst scene name: {first_scene['name']}")
    print(f"First scene description: {first_scene['description']}")

except ValueError as e:
    print(f"Error initializing NuScenes: {e}")
    print("Please ensure 'dataroot' and 'version' are correctly set and the dataset is downloaded.")
except FileNotFoundError as e:
    print(f"Error loading NuScenes data: {e}")
    print("Ensure the dataset is extracted and 'dataroot' points to the correct location.")
    print("Expected structure inside dataroot: sets/nuscenes/<version>/")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →