Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c49642a
add kitti datasets(not test)
Sirokujira Apr 20, 2018
fc1490a
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Apr 23, 2018
7475891
import module miss(modified from KITTI[upper] to kitti[lower])
Sirokujira Apr 23, 2018
af94490
add comment
Sirokujira Apr 25, 2018
d67a76a
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira May 21, 2018
ace06ab
use GetterDataset
Sirokujira May 21, 2018
8c22e49
Additional processing when using GetterDataset class
Sirokujira May 22, 2018
8dfc587
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jun 5, 2018
fb70fd1
functions replace lowercase letters
Sirokujira Jun 6, 2018
7ce5bd6
add pykitti import check logic
Sirokujira Jun 6, 2018
5af09ef
pep8
Sirokujira Jun 6, 2018
42acd2b
flake8
Sirokujira Jun 7, 2018
398d927
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jun 8, 2018
4c63496
flake8(docstring)
Sirokujira Jun 8, 2018
55f1f8a
flake8(docstyle)
Sirokujira Jun 11, 2018
b866091
flake8
Sirokujira Jun 11, 2018
856d706
download base_url changed
Sirokujira Jun 11, 2018
d79c634
check tracklets(It exists only in the data of 2011_09_26)
Sirokujira Jun 11, 2018
3d9ef78
bug fix(Forget to add ,)
Sirokujira Jun 11, 2018
92a056a
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jun 12, 2018
e0d3a11
use pykitti 0.3.0
Sirokujira Jun 13, 2018
5ff1af5
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jun 20, 2018
89428eb
fix bbox/label empty data.
Sirokujira Jun 20, 2018
8fc3369
sintax miss(:)
Sirokujira Jun 20, 2018
a4fe762
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jun 27, 2018
ad6e84d
use pykitti 0.2.4(revert)
Sirokujira Jun 27, 2018
6474c15
add test condition
Sirokujira Jun 27, 2018
73892d1
test remove
Sirokujira Jun 27, 2018
9fa2e20
test passed data set.
Sirokujira Jun 27, 2018
0f2fa1f
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jul 4, 2018
04e0a59
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jul 10, 2018
55ff302
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Jul 27, 2018
975aab6
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Aug 6, 2018
8c68355
change comment(pykitti use under 0.2.4[0.3.0 data access change])
Sirokujira Aug 7, 2018
624fac6
check pykitti version
Sirokujira Aug 23, 2018
9ad059d
pykitti 0.3.0 Image data set
Sirokujira Aug 23, 2018
7112542
remove print debug
Sirokujira Aug 23, 2018
01e6f78
dataArray parameter change(not use list)
Sirokujira Aug 24, 2018
22b4eee
remove unused package(PIL)
Sirokujira Aug 27, 2018
ee3d998
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Sep 17, 2018
db241a8
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Sep 19, 2018
3112845
check stylecode(flake8)
Sirokujira Sep 19, 2018
10752b9
code style check(flake8)
Sirokujira Sep 19, 2018
bb5df21
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Sep 21, 2018
3e1e8b5
Merge remote-tracking branch 'upstream/master' into add_kitti_dataset
Sirokujira Sep 21, 2018
016b0cc
fix comment
Sirokujira Sep 21, 2018
0fd39df
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Sep 26, 2018
e9e571e
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Oct 5, 2018
a533f85
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Oct 12, 2018
cbb6d05
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Oct 19, 2018
be2123f
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Oct 22, 2018
7907560
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Oct 24, 2018
b4be403
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Oct 30, 2018
a5763e1
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Oct 31, 2018
786197a
flake8 check
Sirokujira Oct 31, 2018
9e72e97
Merge remote-tracking branch 'remotes/upstream/master' into add_kitti…
Sirokujira Nov 2, 2018
4396fc1
Changed download folder path to use lower case letters.
Sirokujira Nov 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chainercv/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
from chainercv.datasets.cub.cub_utils import cub_label_names # NOQA
from chainercv.datasets.directory_parsing_label_dataset import directory_parsing_label_names # NOQA
from chainercv.datasets.directory_parsing_label_dataset import DirectoryParsingLabelDataset # NOQA
from chainercv.datasets.kitti.kitti_bbox_dataset import KITTIBboxDataset # NOQA
from chainercv.datasets.kitti.kitti_utils import kitti_bbox_label_colors # NOQA
from chainercv.datasets.kitti.kitti_utils import kitti_bbox_label_names # NOQA
from chainercv.datasets.kitti.kitti_utils import kitti_date_lists # NOQA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to expose this object at this namespace?
We only expose _label_names and _colors here.

from chainercv.datasets.kitti.kitti_utils import kitti_date_num_dicts # NOQA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

from chainercv.datasets.kitti.kitti_utils import kitti_ignore_bbox_label_color # NOQA
from chainercv.datasets.kitti.parseTrackletXML import parseXML # NOQA
from chainercv.datasets.mixup_soft_label_dataset import MixUpSoftLabelDataset # NOQA
from chainercv.datasets.online_products.online_products_dataset import online_products_super_label_names # NOQA
from chainercv.datasets.online_products.online_products_dataset import OnlineProductsDataset # NOQA
Expand Down
Empty file.
219 changes: 219 additions & 0 deletions chainercv/datasets/kitti/kitti_bbox_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import os
import warnings

from pkg_resources import get_distribution
from pkg_resources import parse_version

import numpy as np
try:
import pykitti
pykitti_version = get_distribution('pykitti').version
if parse_version(pykitti_version) >= parse_version('0.3.0'):
# pykitti>=0.3.0
_available = True
else:
# pykitti<0.3.0
warnings.warn('not support pykitti version : ' + pykitti_version)
_available = False
except ImportError:
_available = False

from chainercv.chainer_experimental.datasets.sliceable import GetterDataset
from chainercv.datasets.kitti.kitti_utils import get_kitti_label
from chainercv.datasets.kitti.kitti_utils import get_kitti_nosync_data
from chainercv.datasets.kitti.kitti_utils import get_kitti_sync_data
from chainercv.datasets.kitti.kitti_utils import get_kitti_tracklets
from chainercv.datasets.kitti.kitti_utils import kitti_date_lists
from chainercv.datasets.kitti.kitti_utils import kitti_date_num_dicts


def _check_available():
if not _available:
raise ValueError(
'pykitti is not installed in your environment,'
'so the dataset cannot be loaded.'
'Please install pykitti to load dataset.\n\n'
'$ pip install pykitti>=0.3.0')


class KITTIBboxDataset(GetterDataset):

"""Bounding box dataset for `KITTI dataset`_.
.. _`KITTI dataset`: http://www.cvlibs.net/datasets/kitti/raw_data.php
Args:
data_dir (string): Path to the root of the training data. If this is
:obj:`auto`, this class will automatically download data for you
under :obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/kitti`.
date ({'2011_09_26', '2011_09_28', '2011_09_29',
'2011_09_30', '2011_10_03'}):
reference Calibration datas.
drive_num ({'0xxx'}): get datas drive No.
sync (bool): get timer sync/nosync data.
is_left (bool): left/right camera image use 2type.
tracklet (bool): 3d bblox data. date only 2011_09_26.
This dataset returns the following data.
.. csv-table::
:header: name, shape, dtype, format
:obj:`img`, ":math:`(3, H, W)`", :obj:`float32`, \
"RGB, :math:`[0, 255]`"
:obj:`bbox` [#kitti_bbox_1]_, ":math:`(R, 4)`", :obj:`float32`, \
":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
:obj:`label`, scalar, :obj:`int32`, ":math:`[0, \#class - 1]`"
.. [#kitti_bbox_1] If :obj:`tracklet = True`, \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment true?

:obj:`bbox` and :obj:`label` contain crowded instances.
When queried by an index, if :obj:`tracklet == True`,
this dataset returns a corresponding
:obj:`img, bbox, label`, a tuple of an image, bounding boxes, labels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make two classes: KITTIBboxDataset and KITTIImageDataset?
It is confusing that when tracklet=False, the dataset never returns unempty bounding box or label even though it is named as BboxDataset.
KITTIBboxDataset should only support 2011_09_26, and KITTIImageDataset should support all the other dates.
Also, if you don't want to, you do not need to implement KITTIImageDataset.

We have two classes for Cityscapes as well because subset of the dataset does not contain annotation.

Please see more detail in the Fig. 6 of the summary paper [#]_.
.. [#] Andreas Geiger and Philip Lenz \
and Christoph Stiller and Raquel Urtasun. \
`Vision meets Robotics: The KITTI Dataset \
<http://www.cvlibs.net/publications/Geiger2013IJRR.pdf>`_. \
Geiger2013IJRR.
"""

def __init__(self, data_dir='auto', date='', drive_num='',
sync=True, is_left=True, tracklet=False):
super(KITTIBboxDataset, self).__init__()

_check_available()

self.sync = sync
self.is_left = is_left

if date not in kitti_date_lists:
raise ValueError('\'date\' argment must be one of the ' +
str(kitti_date_lists) + 'values.')

# date(key map)
# if drive_num not in ['0001', '0002', ...]:
if drive_num not in kitti_date_num_dicts[date]:
raise ValueError('\'drive_num\' argment must be one of the ' +
str(kitti_date_num_dicts[date]) + 'values.')

if date == '2011_09_26':
self.tracklet = tracklet
else:
self.tracklet = False

if data_dir == 'auto':
if sync is True:
# download sync data
data_dir = get_kitti_sync_data(
os.path.join('pfnet', 'chainercv', 'kitti'),
date, drive_num, self.tracklet)
else:
# download nosync data
data_dir = get_kitti_nosync_data(
os.path.join('pfnet', 'chainercv', 'kitti'),
date, drive_num, self.tracklet)

if not os.path.exists(data_dir) or not os.path.exists(data_dir):
raise ValueError(
'kitti dataset does not exist at the expected location.'
'Please download it from http://www.cvlibs.net/datasets/kitti/'
'Then place directory at {}.'
.format(os.path.join(data_dir, date + '_drive_' + drive_num)))

# use pykitti
self.dataset = pykitti.raw(
data_dir, date, drive_num, frames=None, imformat='cv2')

# current camera calibration R/P settings.
if self.is_left is True:
# img02
self.cur_rotation_matrix = self.dataset.calib.R_rect_20
self.cur_position_matrix = self.dataset.calib.P_rect_20
# pykitti>=0.3.0
# get PIL Image
# convert from PIL.Image to numpy
dataArray = []
for cam2 in self.dataset.cam2:
data = np.asarray(cam2)
# Convert RGB to BGR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if len(data.shape) > 2:
data = data[:, :, ::-1]
dataArray.append(data)

self.imgs = dataArray
pass
else:
# img03
self.cur_rotation_matrix = self.dataset.calib.R_rect_30
self.cur_position_matrix = self.dataset.calib.P_rect_30
# pykitti>=0.3.0
# get PIL Image
# convert from PIL.Image to numpy
dataArray = []
for cam2 in self.dataset.cam2:
data = np.asarray(cam2)
# Convert RGB to BGR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this comment be the opposite?

if len(data.shape) > 2:
data = data[:, :, ::-1]
dataArray.append(data)

self.imgs = dataArray
pass

# get object info(type/area/bbox/...)
if self.tracklet is True:
self.tracklets = get_kitti_tracklets(data_dir, date, drive_num)
else:
self.tracklets = None

self.bboxes, self.labels = get_kitti_label(
self.tracklets, self.dataset.calib,
self.cur_rotation_matrix, self.cur_position_matrix,
self.__len__())

self.add_getter('img', self._get_image)
self.add_getter(['bbox', 'label'], self._get_annotations)
keys = ('img', 'bbox', 'label')
self.keys = keys

def __len__(self):
return len(self.imgs)

def _get_image(self, i):
img = self.imgs[i]
# convert data is utils.read_image function return values
if img.ndim == 2:
# reshape (H, W) -> (1, H, W)
return img[np.newaxis]
else:
# pykitti img data
# transpose (H, W, C) -> (C, H, W)
return img.transpose((2, 0, 1))

def _get_annotations(self, i):
bbox = self.bboxes
label = self.labels

# convert list to ndarray
if len(bbox[i]) == 0:
# NG
# bbox[i] = [[0.0, 0.0, 0.0, 0.0]]
# Data Padding(Pass Bbox Test)
# bbox[i] = [[0.0, 0.0, 0.01, 0.01]]
np_bbox = np.zeros((0, 4), dtype=np.float32)
else:
np_bbox = np.array(bbox[i], dtype=np.float32)

if len(label[i]) == 0:
# Data Padding(Pass Bbox Test)
# label[i] = [0]
np_label = np.zeros(0, dtype=np.int32)
else:
np_label = np.array(label[i], dtype=np.int32)

return np_bbox, np_label
Loading