|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""NYU-Depth V2.""" |
|
|
|
|
|
import io |
|
|
|
import datasets |
|
import h5py |
|
import numpy as np |
|
|
|
_CITATION = """\ |
|
@inproceedings{Silberman:ECCV12, |
|
author = {Nathan Silberman, Derek Hoiem, Pushmeet Kohli and Rob Fergus}, |
|
title = {Indoor Segmentation and Support Inference from RGBD Images}, |
|
booktitle = {ECCV}, |
|
year = {2012} |
|
} |
|
@inproceedings{icra_2019_fastdepth, |
|
author = {Wofk, Diana and Ma, Fangchang and Yang, Tien-Ju and Karaman, Sertac and Sze, Vivienne}, |
|
title = {FastDepth: Fast Monocular Depth Estimation on Embedded Systems}, |
|
booktitle = {IEEE International Conference on Robotics and Automation (ICRA)}, |
|
year = {2019} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The NYU-Depth V2 data set is comprised of video sequences from a variety of indoor scenes as recorded by both the RGB and Depth cameras from the Microsoft Kinect. |
|
""" |
|
|
|
_HOMEPAGE = "https://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html" |
|
|
|
_LICENSE = "Apace 2.0 License" |
|
|
|
_URLS = { |
|
"train": [f"data/train-{i:06d}.tar" for i in range(12)], |
|
"val": [f"data/val-{i:06d}.tar" for i in range(2)], |
|
} |
|
|
|
_IMG_EXTENSIONS = [".h5"] |
|
|
|
|
|
class NYUDepthV2(datasets.GeneratorBasedBuilder): |
|
"""NYU-Depth V2 dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{"image": datasets.Image(), "depth_map": datasets.Image()} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _is_image_file(self, filename): |
|
|
|
return any(filename.endswith(extension) for extension in _IMG_EXTENSIONS) |
|
|
|
def _h5_loader(self, bytes_stream): |
|
|
|
f = io.BytesIO(bytes_stream) |
|
h5f = h5py.File(f, "r") |
|
rgb = np.array(h5f["rgb"]) |
|
rgb = np.transpose(rgb, (1, 2, 0)) |
|
depth = np.array(h5f["depth"]) |
|
return rgb, depth |
|
|
|
def _split_generators(self, dl_manager): |
|
archives = dl_manager.download(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"archives": [ |
|
dl_manager.iter_archive(archive) for archive in archives["train"] |
|
] |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"archives": [ |
|
dl_manager.iter_archive(archive) for archive in archives["val"] |
|
] |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, archives): |
|
idx = 0 |
|
for archive in archives: |
|
for path, file in archive: |
|
if self._is_image_file(path): |
|
image, depth = self._h5_loader(file.read()) |
|
yield idx, {"image": image, "depth_map": depth} |
|
idx += 1 |
|
|