|
import io |
|
import itertools as it |
|
import numpy as np |
|
import datasets as d |
|
|
|
|
|
_DESCRIPTION = """\ |
|
The Dropjects dataset was created at the Chair of Cyber-Physical Systems in Production \ |
|
Engineering at the Technical University of Munich. |
|
""" |
|
|
|
SUBSETS = [ |
|
"omni", |
|
"cps", |
|
"linemod", |
|
"ycbv", |
|
"homebreweddb", |
|
"hope", |
|
"tless", |
|
] |
|
|
|
NUM_SHARDS = { |
|
"cps": 1000, |
|
"ycbv": 1000, |
|
"linemod": 1000, |
|
"tless": 1000, |
|
"omni": 10_000, |
|
} |
|
|
|
|
|
BASE_PATH = "https://huggingface.co/datasets/LukasDb/dropjects/resolve/main/data/train/{subset}/{shard}.tar" |
|
|
|
|
|
h = 1440 |
|
w = 2560 |
|
|
|
|
|
class Dropjects(d.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = list(d.BuilderConfig(name=x) for x in SUBSETS) |
|
|
|
def _info(self): |
|
|
|
features = d.Features( |
|
{ |
|
|
|
"rgb": d.Array3D((h, w, 3), dtype="uint8"), |
|
"rgb_R": d.Array3D((h, w, 3), dtype="uint8"), |
|
"depth": d.Array2D((h, w), dtype="float32"), |
|
"depth_R": d.Array2D((h, w), dtype="float32"), |
|
"mask": d.Array2D((h, w), dtype="int32"), |
|
"obj_ids": d.Sequence(d.Value("int32")), |
|
"obj_classes": d.Sequence(d.Value("string")), |
|
"obj_pos": d.Sequence(d.Sequence(d.Value("float32"))), |
|
"obj_rot": d.Sequence(d.Sequence(d.Value("float32"))), |
|
"obj_bbox_obj": d.Sequence(d.Sequence(d.Value("int32"))), |
|
"obj_bbox_visib": d.Sequence(d.Sequence(d.Value("int32"))), |
|
"cam_location": d.Sequence(d.Value("float32")), |
|
"cam_rotation": d.Sequence(d.Value("float32")), |
|
"cam_matrix": d.Array2D((3, 3), dtype="float32"), |
|
"obj_px_count_all": d.Sequence(d.Value("int32")), |
|
"obj_px_count_valid": d.Sequence(d.Value("int32")), |
|
"obj_px_count_visib": d.Sequence(d.Value("int32")), |
|
"obj_visib_fract": d.Sequence(d.Value("float32")), |
|
} |
|
) |
|
return d.DatasetInfo( |
|
description=_DESCRIPTION, |
|
citation="", |
|
homepage="", |
|
license="cc", |
|
features=features, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
subset = self.config.name |
|
|
|
archive_paths = [ |
|
BASE_PATH.format(subset=subset, shard=i) for i in range(NUM_SHARDS[subset]) |
|
] |
|
|
|
downloaded = dl_manager.download(archive_paths) |
|
|
|
return [ |
|
d.SplitGenerator( |
|
name=d.Split.TRAIN, |
|
gen_kwargs={"tars": [dl_manager.iter_archive(d) for d in downloaded]}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, tars): |
|
sample = {} |
|
id = None |
|
|
|
for tar in tars: |
|
for file_path, file_obj in tar: |
|
new_id = file_path.split(".")[0] |
|
if id is None: |
|
id = new_id |
|
else: |
|
if id != new_id: |
|
yield id, sample |
|
sample = {} |
|
id = new_id |
|
|
|
key = file_path.split(".")[1] |
|
|
|
bytes = io.BytesIO(file_obj.read()) |
|
value = np.load(bytes, allow_pickle=False) |
|
|
|
sample[key] = value |
|
|