Upload dropjects.py with huggingface_hub
Browse files- dropjects.py +110 -0
dropjects.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import itertools as it
|
| 3 |
+
import numpy as np
|
| 4 |
+
import datasets as d
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_DESCRIPTION = """\
|
| 8 |
+
The Dropjects dataset was created at the Chair of Cyber-Physical Systems in Production \
|
| 9 |
+
Engineering at the Technical University of Munich.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
SUBSETS = [
|
| 13 |
+
"omni",
|
| 14 |
+
"cps",
|
| 15 |
+
"linemod",
|
| 16 |
+
"ycbv",
|
| 17 |
+
"homebreweddb",
|
| 18 |
+
"hope",
|
| 19 |
+
"tless",
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
NUM_SHARDS = {
|
| 23 |
+
"cps": 1000,
|
| 24 |
+
"ycbv": 1000,
|
| 25 |
+
"linemod": 1000,
|
| 26 |
+
"tless": 1000,
|
| 27 |
+
"omni": 10_000,
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
BASE_PATH = "https://huggingface.co/datasets/LukasDb/dropjects/resolve/main/data/train/{subset}/{shard}.tar"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
h = 1440
|
| 35 |
+
w = 2560
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class Dropjects(d.GeneratorBasedBuilder):
|
| 39 |
+
BUILDER_CONFIGS = list(d.BuilderConfig(name=x) for x in SUBSETS)
|
| 40 |
+
|
| 41 |
+
def _info(self):
|
| 42 |
+
|
| 43 |
+
features = d.Features(
|
| 44 |
+
{
|
| 45 |
+
# TODO at least the resolution is different
|
| 46 |
+
"rgb": d.Array3D((h, w, 3), dtype="uint8"),
|
| 47 |
+
"rgb_R": d.Array3D((h, w, 3), dtype="uint8"),
|
| 48 |
+
"depth": d.Array2D((h, w), dtype="float32"),
|
| 49 |
+
"depth_R": d.Array2D((h, w), dtype="float32"),
|
| 50 |
+
"mask": d.Array2D((h, w), dtype="int32"),
|
| 51 |
+
"obj_ids": d.Sequence(d.Value("int32")),
|
| 52 |
+
"obj_classes": d.Sequence(d.Value("string")),
|
| 53 |
+
"obj_pos": d.Sequence(d.Sequence(d.Value("float32"))),
|
| 54 |
+
"obj_rot": d.Sequence(d.Sequence(d.Value("float32"))),
|
| 55 |
+
"obj_bbox_obj": d.Sequence(d.Sequence(d.Value("int32"))),
|
| 56 |
+
"obj_bbox_visib": d.Sequence(d.Sequence(d.Value("int32"))),
|
| 57 |
+
"cam_location": d.Sequence(d.Value("float32")),
|
| 58 |
+
"cam_rotation": d.Sequence(d.Value("float32")),
|
| 59 |
+
"cam_matrix": d.Array2D((3, 3), dtype="float32"),
|
| 60 |
+
"obj_px_count_all": d.Sequence(d.Value("int32")),
|
| 61 |
+
"obj_px_count_valid": d.Sequence(d.Value("int32")),
|
| 62 |
+
"obj_px_count_visib": d.Sequence(d.Value("int32")),
|
| 63 |
+
"obj_visib_fract": d.Sequence(d.Value("float32")),
|
| 64 |
+
}
|
| 65 |
+
)
|
| 66 |
+
return d.DatasetInfo(
|
| 67 |
+
description=_DESCRIPTION,
|
| 68 |
+
citation="", # TODO
|
| 69 |
+
homepage="", # TODO
|
| 70 |
+
license="cc",
|
| 71 |
+
features=features,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
def _split_generators(self, dl_manager):
|
| 75 |
+
subset = self.config.name
|
| 76 |
+
|
| 77 |
+
archive_paths = [
|
| 78 |
+
BASE_PATH.format(subset=subset, shard=i) for i in range(NUM_SHARDS[subset])
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
downloaded = dl_manager.download(archive_paths)
|
| 82 |
+
|
| 83 |
+
return [
|
| 84 |
+
d.SplitGenerator(
|
| 85 |
+
name=d.Split.TRAIN,
|
| 86 |
+
gen_kwargs={"tars": [dl_manager.iter_archive(d) for d in downloaded]},
|
| 87 |
+
),
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
def _generate_examples(self, tars):
|
| 91 |
+
sample = {}
|
| 92 |
+
id = None
|
| 93 |
+
|
| 94 |
+
for tar in tars:
|
| 95 |
+
for file_path, file_obj in tar:
|
| 96 |
+
new_id = file_path.split(".")[0]
|
| 97 |
+
if id is None:
|
| 98 |
+
id = new_id
|
| 99 |
+
else:
|
| 100 |
+
if id != new_id:
|
| 101 |
+
yield id, sample
|
| 102 |
+
sample = {}
|
| 103 |
+
id = new_id
|
| 104 |
+
|
| 105 |
+
key = file_path.split(".")[1]
|
| 106 |
+
|
| 107 |
+
bytes = io.BytesIO(file_obj.read())
|
| 108 |
+
value = np.load(bytes, allow_pickle=False)
|
| 109 |
+
|
| 110 |
+
sample[key] = value
|