<!-- # hard line break macro for HTML -->

# fiftyone.utils.kitti

Utilities for working with datasets in
[KITTI format](http://www.cvlibs.net/datasets/kitti/eval_object.php).

Copyright 2017-2026, Voxel51, Inc.
<br/>
[voxel51.com](https://voxel51.com/)
<br/>
<br/>

**Classes:**

| [`KITTIDetectionDatasetImporter`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter)([dataset_dir, ...])   | Importer for KITTI detection datasets stored on disk.    |
|--------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [`KITTIDetectionDatasetExporter`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter)([export_dir, ...])    | Exporter that writes KITTI detection datasets to disk.   |
| [`KITTIAnnotationWriter`](#fiftyone.utils.kitti.KITTIAnnotationWriter)()                                     | Class for writing annotations in KITTI detection format. |

**Functions:**

| [`load_kitti_detection_annotations`](#fiftyone.utils.kitti.load_kitti_detection_annotations)(txt_path, ...)   | Loads the KITTI detection annotations from the given TXT file.   |
|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| [`download_kitti_multiview_dataset`](#fiftyone.utils.kitti.download_kitti_multiview_dataset)(dataset_dir)     | Downloads and prepares the multiview KITTI dataset.              |
| [`download_kitti_detection_dataset`](#fiftyone.utils.kitti.download_kitti_detection_dataset)(dataset_dir)     | Downloads the KITTI object detection dataset from the web.       |

### *class* fiftyone.utils.kitti.KITTIDetectionDatasetImporter(dataset_dir=None, data_path=None, labels_path=None, include_all_data=False, extra_attrs=True, shuffle=False, seed=None, max_samples=None)

Bases: [`LabeledImageDatasetImporter`](fiftyone.utils.data.importers.md#fiftyone.utils.data.importers.LabeledImageDatasetImporter), [`ImportPathsMixin`](fiftyone.utils.data.importers.md#fiftyone.utils.data.importers.ImportPathsMixin)

Importer for KITTI detection datasets stored on disk.

See [this page](../user_guide/import_datasets.md#kittidetectiondataset-import) for format details.

* **Parameters:**
  * **dataset_dir** (*None*) – the dataset directory. If omitted, `data_path`
    and/or `labels_path` must be provided
  * **data_path** (*None*) – 

    an optional parameter that enables explicit control
    over the location of the media. Can be any of the following:
    - a folder name like `"data"` or `"data/"` specifying a
      subfolder of `dataset_dir` where the media files reside
    - an absolute directory path where the media files reside. In
      this case, the `dataset_dir` has no effect on the location of
      the data
    - a filename like `"data.json"` specifying the filename of the
      JSON data manifest file in `dataset_dir`
    - an absolute filepath specifying the location of the JSON data
      manifest. In this case, `dataset_dir` has no effect on the
      location of the data
    - a dict mapping filenames to absolute filepaths

    If None, this parameter will default to whichever of `data/` or
    `data.json` exists in the dataset directory
  * **labels_path** (*None*) – 

    an optional parameter that enables explicit control
    over the location of the labels. Can be any of the following:
    - a folder name like `"labels"` or `"labels/"` specifying the
      location of the labels in `dataset_dir`
    - an absolute folder path to the labels. In this case,
      `dataset_dir` has no effect on the location of the labels

    If None, the parameter will default to `labels/`
  * **include_all_data** (*False*) – whether to generate samples for all images in
    the data directory (True) rather than only creating samples for
    images with label entries (False)
  * **extra_attrs** (*True*) – 

    whether to load extra annotation attributes onto
    the imported labels. Supported values are:
    - `True`: load all extra attributes found
    - `False`: do not load extra attributes
    - a name or list of names of specific attributes to load
  * **shuffle** (*False*) – whether to randomly shuffle the order in which the
    samples are imported
  * **seed** (*None*) – a random seed to use when shuffling
  * **max_samples** (*None*) – a maximum number of samples to import. By default,
    all samples are imported

**Attributes:**

| [`has_dataset_info`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter.has_dataset_info)     | Whether this importer produces a dataset info dictionary.                                                                                                         |
|------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`has_image_metadata`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter.has_image_metadata) | Whether this importer produces [`fiftyone.core.metadata.ImageMetadata`](fiftyone.core.metadata.md#fiftyone.core.metadata.ImageMetadata) instances for each image. |
| [`label_cls`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter.label_cls)                   | The [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) class(es) returned by this importer.                                       |

**Methods:**

| [`setup`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter.setup)()                         | Performs any necessary setup before importing the first sample in the dataset.                      |
|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
| [`close`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter.close)(\*args)                   | Performs any necessary actions after the last sample has been imported.                             |
| [`get_dataset_info`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter.get_dataset_info)()   | Returns the dataset info for the dataset.                                                           |
| [`get_media_sources`](#fiftyone.utils.kitti.KITTIDetectionDatasetImporter.get_media_sources)() | Returns the media-source entries the importing dataset records before any sample is added, or None. |

#### *property* has_dataset_info

Whether this importer produces a dataset info dictionary.

#### *property* has_image_metadata

Whether this importer produces
[`fiftyone.core.metadata.ImageMetadata`](fiftyone.core.metadata.md#fiftyone.core.metadata.ImageMetadata) instances for each image.

#### *property* label_cls

The [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) class(es) returned by this
importer.

This can be any of the following:

- a [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) class. In this case, the
  importer is guaranteed to return labels of this type
- a list or tuple of [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) classes. In
  this case, the importer can produce a single label field of any of
  these types
- a dict mapping keys to [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) classes.
  In this case, the importer will return label dictionaries with keys
  and value-types specified by this dictionary. Not all keys need be
  present in the imported labels
- `None`. In this case, the importer makes no guarantees about the
  labels that it may return

#### setup()

Performs any necessary setup before importing the first sample in
the dataset.

This method is called when the importer’s context manager interface is
entered, `DatasetImporter.__enter__()`.

#### close(\*args)

Performs any necessary actions after the last sample has been
imported.

This method is called when the importer’s context manager interface is
exited, `DatasetImporter.__exit__()`.

* **Parameters:**
  **\*args** – the arguments to `DatasetImporter.__exit__()`

#### get_dataset_info()

Returns the dataset info for the dataset.

By convention, this method should be called after all samples in the
dataset have been imported.

* **Returns:**
  a dict of dataset info

#### get_media_sources()

Returns the media-source entries the importing dataset records
before any sample is added, or None.

Only importers of media-reference-backed samples provide these; see
[`fiftyone.utils.lerobot.LeRobotDatasetImporter`](fiftyone.utils.lerobot.md#fiftyone.utils.lerobot.LeRobotDatasetImporter).

### *class* fiftyone.utils.kitti.KITTIDetectionDatasetExporter(export_dir=None, data_path=None, labels_path=None, export_media=None, rel_dir=None, image_format=None)

Bases: [`LabeledImageDatasetExporter`](fiftyone.utils.data.exporters.md#fiftyone.utils.data.exporters.LabeledImageDatasetExporter), [`ExportPathsMixin`](fiftyone.utils.data.exporters.md#fiftyone.utils.data.exporters.ExportPathsMixin)

Exporter that writes KITTI detection datasets to disk.

See [this page](../user_guide/export_datasets.md#kittidetectiondataset-export) for format details.

* **Parameters:**
  * **export_dir** (*None*) – the directory to write the export. This has no
    effect if `data_path` and `labels_path` are absolute paths
  * **data_path** (*None*) – 

    an optional parameter that enables explicit control
    over the location of the exported media. Can be any of the
    following:
    - a folder name like `"data"` or `"data/"` specifying a
      subfolder of `export_dir` in which to export the media
    - an absolute directory path in which to export the media. In
      this case, the `export_dir` has no effect on the location of
      the data
    - a JSON filename like `"data.json"` specifying the filename of
      the manifest file in `export_dir` generated when
      `export_media` is `"manifest"`
    - an absolute filepath specifying the location to write the JSON
      manifest file when `export_media` is `"manifest"`. In this
      case, `export_dir` has no effect on the location of the data

    If None, the default value of this parameter will be chosen based
    on the value of the `export_media` parameter
  * **labels_path** (*None*) – 

    an optional parameter that enables explicit control
    over the location of the exported labels. Can be any of the
    following:
    - a folder name like `"labels"` or `"labels/"` specifying the
      location in `export_dir` in which to export the labels
    - an absolute folder path to which to export the labels. In this
      case, the `export_dir` has no effect on the location of the
      labels

    If None, the labels will be exported into `export_dir` using the
    default folder name
  * **export_media** (*None*) – 

    controls how to export the raw media. The
    supported values are:
    - `True`: copy all media files into the output directory
    - `False`: don’t export media
    - `"move"`: move all media files into the output directory
    - `"symlink"`: create symlinks to the media files in the output
      directory
    - `"manifest"`: create a `data.json` in the output directory
      that maps UUIDs used in the labels files to the filepaths of
      the source media, rather than exporting the actual media

    If None, the default value of this parameter will be chosen based
    on the value of the `data_path` parameter
  * **rel_dir** (*None*) – an optional relative directory to strip from each input
    filepath to generate a unique identifier for each image. When
    exporting media, this identifier is joined with `data_path` and
    `labels_path` to generate output paths for each exported image
    and labels file. This argument allows for populating nested
    subdirectories that match the shape of the input paths. The path is
    converted to an absolute path (if necessary) via
    [`fiftyone.core.storage.normalize_path()`](fiftyone.core.storage.md#fiftyone.core.storage.normalize_path)
  * **image_format** (*None*) – the image format to use when writing in-memory
    images to disk. By default, `fiftyone.config.default_image_ext`
    is used

**Attributes:**

| [`requires_image_metadata`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.requires_image_metadata)   | Whether this exporter requires [`fiftyone.core.metadata.ImageMetadata`](fiftyone.core.metadata.md#fiftyone.core.metadata.ImageMetadata) instances for each sample being exported.   |
|------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`label_cls`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.label_cls)                               | The [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) class(es) exported by this exporter.                                                         |

**Methods:**

| [`setup`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.setup)()                                                 | Performs any necessary setup before exporting the first sample in the dataset.                                                                                                                  |
|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`export_sample`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.export_sample)(image_or_path, detections[, ...]) | Exports the given sample to the dataset.                                                                                                                                                        |
| [`close`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.close)(\*args)                                           | Performs any necessary actions after the last sample has been exported.                                                                                                                         |
| [`log_collection`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.log_collection)(sample_collection)              | Logs any relevant information about the [`fiftyone.core.collections.SampleCollection`](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection) whose samples will be exported. |

#### *property* requires_image_metadata

Whether this exporter requires
[`fiftyone.core.metadata.ImageMetadata`](fiftyone.core.metadata.md#fiftyone.core.metadata.ImageMetadata) instances for each sample
being exported.

#### *property* label_cls

The [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) class(es) exported by this
exporter.

This can be any of the following:

- a [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) class. In this case, the
  exporter directly exports labels of this type
- a list or tuple of [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) classes. In
  this case, the exporter can export a single label field of any of
  these types
- a dict mapping keys to [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) classes.
  In this case, the exporter can handle label dictionaries with
  value-types specified by this dictionary. Not all keys need be
  present in the exported label dicts
- `None`. In this case, the exporter makes no guarantees about the
  labels that it can export

#### setup()

Performs any necessary setup before exporting the first sample in
the dataset.

This method is called when the exporter’s context manager interface is
entered, `DatasetExporter.__enter__()`.

#### export_sample(image_or_path, detections, metadata=None)

Exports the given sample to the dataset.

* **Parameters:**
  * **image_or_path** – an image or the path to the image on disk
  * **label** – an instance of [`label_cls()`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.label_cls), or a dictionary mapping
    field names to [`fiftyone.core.labels.Label`](fiftyone.core.labels.md#fiftyone.core.labels.Label) instances,
    or `None` if the sample is unlabeled
  * **metadata** (*None*) – a [`fiftyone.core.metadata.ImageMetadata`](fiftyone.core.metadata.md#fiftyone.core.metadata.ImageMetadata)
    instance for the sample. Only required when
    [`requires_image_metadata()`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.requires_image_metadata) is `True`

#### close(\*args)

Performs any necessary actions after the last sample has been
exported.

This method is called when the exporter’s context manager interface is
exited, `DatasetExporter.__exit__()`.

* **Parameters:**
  **\*args** – the arguments to `DatasetExporter.__exit__()`

#### log_collection(sample_collection)

Logs any relevant information about the
[`fiftyone.core.collections.SampleCollection`](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection) whose samples will
be exported.

Subclasses can optionally implement this method if their export format
can record information such as the
[`fiftyone.core.collections.SampleCollection.info()`](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.info) of the
collection being exported.

By convention, this method must be optional; i.e., if it is not called
before the first call to [`export_sample()`](#fiftyone.utils.kitti.KITTIDetectionDatasetExporter.export_sample), then the exporter must
make do without any information about the
[`fiftyone.core.collections.SampleCollection`](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection) (which may not be
available, for example, if the samples being exported are not stored in
a collection).

* **Parameters:**
  **sample_collection** – the
  [`fiftyone.core.collections.SampleCollection`](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection) whose
  samples will be exported

### *class* fiftyone.utils.kitti.KITTIAnnotationWriter

Bases: `object`

Class for writing annotations in KITTI detection format.

See [this page](../user_guide/export_datasets.md#kittidetectiondataset-export) for format details.

**Methods:**

| [`write`](#fiftyone.utils.kitti.KITTIAnnotationWriter.write)(detections, metadata, txt_path)   | Writes the detections to disk.   |
|------------------------------------------------------------------------------------------------|----------------------------------|

#### write(detections, metadata, txt_path)

Writes the detections to disk.

* **Parameters:**
  * **detections** – a [`fiftyone.core.labels.Detections`](fiftyone.core.labels.md#fiftyone.core.labels.Detections) instance
  * **metadata** – a [`fiftyone.core.metadata.ImageMetadata`](fiftyone.core.metadata.md#fiftyone.core.metadata.ImageMetadata) instance
  * **txt_path** – the path to write the annotation TXT file

### fiftyone.utils.kitti.load_kitti_detection_annotations(txt_path, frame_size, extra_attrs=True)

Loads the KITTI detection annotations from the given TXT file.

See [this page](../user_guide/import_datasets.md#kittidetectiondataset-import) for format details.

* **Parameters:**
  * **txt_path** – the path to the annotations TXT file
  * **frame_size** – the `(width, height)` of the image
  * **extra_attrs** (*True*) – 

    whether to load extra annotation attributes onto
    the imported labels. Supported values are:
    - `True`: load all extra attributes found
    - `False`: do not load extra attributes
    - a name or list of names of specific attributes to load
* **Returns:**
  a `fiftyone.core.detections.Detections` instance

### fiftyone.utils.kitti.download_kitti_multiview_dataset(dataset_dir, splits=None, scratch_dir=None, overwrite=False, cleanup=False, num_workers=None)

Downloads and prepares the multiview KITTI dataset.

The dataset will be organized on disk in as follows, with each split stored
in [FiftyOneDataset format](../user_guide/import_datasets.md#fiftyonedataset-import):

```default
dataset_dir/
    train/
        labels/
            000000.txt
            000001.txt
            ...
        calib/
            000000.txt
            000001.txt
            ...
        left/
            000000.png
            000001.png
            ...
        right/
            000000.png
            000001.png
            ...
        velodyne/
            000000.bin
            000001.bin
            ...
        pcd/
            000000.pcd
            000001.pcd
            ...
        metadata.json
        samples.json
    test/
        ...
```

* **Parameters:**
  * **dataset_dir** – the directory in which to construct the dataset
  * **splits** (*None*) – the split or list of splits to download. Supported
    values are `("train", "test")`
  * **scratch_dir** (*None*) – a scratch directory to use to download any necessary
    temporary files
  * **overwrite** (*False*) – whether to redownload/regenerate files if they
    already exist
  * **cleanup** (*False*) – whether to delete the downloaded zips and scratch
    directory
  * **num_workers** (*None*) – a suggested number of processes to use when
    converting LiDAR to PCD

### fiftyone.utils.kitti.download_kitti_detection_dataset(dataset_dir, splits=None, scratch_dir=None, overwrite=False, cleanup=False)

Downloads the KITTI object detection dataset from the web.

The dataset will be organized on disk in as follows:

```default
dataset_dir/
    train/
        data/
            000000.png
            000001.png
            ...
        labels/
            000000.txt
            000001.txt
            ...
    test/
        data/
            000000.png
            000001.png
            ...
```

* **Parameters:**
  * **dataset_dir** – the directory in which to construct the dataset
  * **splits** (*None*) – the split or list of splits to download. Supported
    values are `("train", "test")`
  * **scratch_dir** (*None*) – a scratch directory to use to download any necessary
    temporary files
  * **overwrite** (*False*) – whether to redownload the zips if they already exist
  * **cleanup** (*False*) – whether to delete the downloaded zips and scratch
    directory
