Add KITTI format (#3757)
parent
cc801b21ed
commit
e4aa0ea15a
@ -0,0 +1,53 @@
|
|||||||
|
# Copyright (C) 2021 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import os.path as osp
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
|
from datumaro.components.dataset import Dataset
|
||||||
|
from datumaro.plugins.kitti_format.format import KittiPath, write_label_map
|
||||||
|
from pyunpack import Archive
|
||||||
|
|
||||||
|
from cvat.apps.dataset_manager.bindings import (GetCVATDataExtractor,
|
||||||
|
ProjectData, import_dm_annotations)
|
||||||
|
from cvat.apps.dataset_manager.util import make_zip_archive
|
||||||
|
|
||||||
|
from .registry import dm_env, exporter, importer
|
||||||
|
from .utils import make_colormap
|
||||||
|
|
||||||
|
|
||||||
|
@exporter(name='KITTI', ext='ZIP', version='1.0')
|
||||||
|
def _export(dst_file, instance_data, save_images=False):
|
||||||
|
dataset = Dataset.from_extractors(GetCVATDataExtractor(instance_data,
|
||||||
|
include_images=save_images), env=dm_env)
|
||||||
|
|
||||||
|
with TemporaryDirectory() as tmp_dir:
|
||||||
|
dataset.transform('polygons_to_masks')
|
||||||
|
dataset.transform('merge_instance_segments')
|
||||||
|
dataset.export(tmp_dir, format='kitti',
|
||||||
|
label_map={k: v[0] for k, v in make_colormap(instance_data).items()},
|
||||||
|
apply_colormap=True, save_images=save_images
|
||||||
|
)
|
||||||
|
|
||||||
|
make_zip_archive(tmp_dir, dst_file)
|
||||||
|
|
||||||
|
@importer(name='KITTI', ext='ZIP', version='1.0')
|
||||||
|
def _import(src_file, instance_data):
|
||||||
|
with TemporaryDirectory() as tmp_dir:
|
||||||
|
Archive(src_file.name).extractall(tmp_dir)
|
||||||
|
|
||||||
|
color_map = {k: v[0] for k, v in make_colormap(instance_data).items()}
|
||||||
|
color_map_path = osp.join(tmp_dir, KittiPath.LABELMAP_FILE)
|
||||||
|
if not osp.isfile(color_map_path):
|
||||||
|
write_label_map(color_map_path, color_map)
|
||||||
|
|
||||||
|
dataset = Dataset.import_from(tmp_dir, format='kitti', env=dm_env)
|
||||||
|
labels_meta = instance_data.meta['project']['labels'] \
|
||||||
|
if isinstance(instance_data, ProjectData) else instance_data.meta['task']['labels']
|
||||||
|
if 'background' not in [label['name'] for _, label in labels_meta]:
|
||||||
|
dataset.filter('/item/annotation[label != "background"]',
|
||||||
|
filter_annotations=True)
|
||||||
|
dataset.transform('masks_to_polygons')
|
||||||
|
|
||||||
|
import_dm_annotations(dataset, instance_data)
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
---
|
||||||
|
linkTitle: 'KITTI'
|
||||||
|
weight: 17
|
||||||
|
---
|
||||||
|
|
||||||
|
# [KITTI](http://www.cvlibs.net/datasets/kitti/)
|
||||||
|
|
||||||
|
- [Format specification for KITTI detection](https://s3.eu-central-1.amazonaws.com/avg-kitti/devkit_object.zip)
|
||||||
|
- [Format specification for KITTI segmentation](https://s3.eu-central-1.amazonaws.com/avg-kitti/devkit_semantics.zip)
|
||||||
|
|
||||||
|
- supported annotations:
|
||||||
|
|
||||||
|
- Rectangles (detection task)
|
||||||
|
- Polygon (segmentation task)
|
||||||
|
|
||||||
|
- supported attributes:
|
||||||
|
|
||||||
|
- `occluded` (both UI option and a separate attribute).
|
||||||
|
Indicates that a significant portion of the object within
|
||||||
|
the bounding box is occluded by another object
|
||||||
|
- `truncated` supported only for rectangles
|
||||||
|
(should be defined for labels as `checkbox` -es).
|
||||||
|
Indicates that the bounding box specified for the object
|
||||||
|
does not correspond to the full extent of the object
|
||||||
|
- 'is_crowd' supported only for polygons
|
||||||
|
(should be defined for labels as `checkbox` -es).
|
||||||
|
Indicates that the annotation covers multiple instances of the same class
|
||||||
|
|
||||||
|
## KITTI annotations export
|
||||||
|
|
||||||
|
Downloaded file: a zip archive of the following structure:
|
||||||
|
|
||||||
|
```
|
||||||
|
└─ annotations.zip/
|
||||||
|
├── label_colors.txt # list of pairs r g b label_name
|
||||||
|
├── labels.txt # list of labels
|
||||||
|
└── default/
|
||||||
|
├── label_2/ # left color camera label files
|
||||||
|
│ ├── <image_name_1>.txt
|
||||||
|
│ ├── <image_name_2>.txt
|
||||||
|
│ └── ...
|
||||||
|
├── instance/ # instance segmentation masks
|
||||||
|
│ ├── <image_name_1>.png
|
||||||
|
│ ├── <image_name_2>.png
|
||||||
|
│ └── ...
|
||||||
|
├── semantic/ # semantic segmentation masks (labels are encoded by its id)
|
||||||
|
│ ├── <image_name_1>.png
|
||||||
|
│ ├── <image_name_2>.png
|
||||||
|
│ └── ...
|
||||||
|
└── semantic_rgb/ # semantic segmentation masks (labels are encoded by its color)
|
||||||
|
├── <image_name_1>.png
|
||||||
|
├── <image_name_2>.png
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
## KITTI annotations import
|
||||||
|
|
||||||
|
You can upload KITTI annotations in two ways:
|
||||||
|
rectangles for the detection task and
|
||||||
|
masks for the segmentation task.
|
||||||
|
|
||||||
|
For detection tasks the uploading archive should have the following structure:
|
||||||
|
|
||||||
|
```
|
||||||
|
└─ annotations.zip/
|
||||||
|
├── labels.txt # optional, labels list for non-original detection labels
|
||||||
|
└── <subset_name>/
|
||||||
|
├── label_2/ # left color camera label files
|
||||||
|
│ ├── <image_name_1>.txt
|
||||||
|
│ ├── <image_name_2>.txt
|
||||||
|
│ └── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
For segmentation tasks the uploading archive should have the following structure:
|
||||||
|
|
||||||
|
```
|
||||||
|
└─ annotations.zip/
|
||||||
|
├── label_colors.txt # optional, color map for non-original segmentation labels
|
||||||
|
└── <subset_name>/
|
||||||
|
├── instance/ # instance segmentation masks
|
||||||
|
│ ├── <image_name_1>.png
|
||||||
|
│ ├── <image_name_2>.png
|
||||||
|
│ └── ...
|
||||||
|
├── semantic/ # optional, semantic segmentation masks (labels are encoded by its id)
|
||||||
|
│ ├── <image_name_1>.png
|
||||||
|
│ ├── <image_name_2>.png
|
||||||
|
│ └── ...
|
||||||
|
└── semantic_rgb/ # optional, semantic segmentation masks (labels are encoded by its color)
|
||||||
|
├── <image_name_1>.png
|
||||||
|
├── <image_name_2>.png
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
All annotation files and masks should have structures
|
||||||
|
that are described in the original format specification.
|
||||||
Loading…
Reference in New Issue