Datasets:
Tasks:
Depth Estimation
Modalities:
Image
Languages:
English
Size:
1K - 10K
ArXiv:
Tags:
depth-estimation
License:
File size: 4,560 Bytes
fb20c38 0c9913a fb20c38 0c9913a fb20c38 0c9913a fb20c38 0c9913a fb20c38 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""NYU-Depth V2."""
import os
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 = {
"depth_estimation": {
"train/val": "http://datasets.lids.mit.edu/fastdepth/data/nyudepthv2.tar.gz",
}
}
_IMG_EXTENSIONS = [".h5"]
class NYUDepthV2(datasets.GeneratorBasedBuilder):
"""NYU-Depth V2 dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="depth_estimation",
version=VERSION,
description="The depth estimation variant.",
),
]
DEFAULT_CONFIG_NAME = "depth_estimation"
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):
# Reference: https://github.com/dwofk/fast-depth/blob/master/dataloaders/dataloader.py#L21-L23
return any(filename.endswith(extension) for extension in _IMG_EXTENSIONS)
def _get_file_paths(self, dir):
# Reference: https://github.com/dwofk/fast-depth/blob/master/dataloaders/dataloader.py#L31-L44
file_paths = []
dir = os.path.expanduser(dir)
for target in sorted(os.listdir(dir)):
d = os.path.join(dir, target)
if not os.path.isdir(d):
continue
for root, _, fnames in sorted(os.walk(d)):
for fname in sorted(fnames):
if self._is_image_file(fname):
path = os.path.join(root, fname)
file_paths.append(path)
return file_paths
def _h5_loader(self, path):
# Reference: https://github.com/dwofk/fast-depth/blob/master/dataloaders/dataloader.py#L8-L13
h5f = h5py.File(path, "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):
urls = _URLS[self.config.name]
base_path = dl_manager.download_and_extract(urls)["train/val"]
train_data_files = self._get_file_paths(
os.path.join(base_path, "nyudepthv2", "train")
)
val_data_files = self._get_file_paths(os.path.join(base_path, "nyudepthv2", "val"))
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepaths": train_data_files},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepaths": val_data_files},
),
]
def _generate_examples(self, filepaths):
for idx, filepath in enumerate(filepaths):
image, depth = self._h5_loader(filepath)
yield idx, {"image": image, "depth_map": depth}
|