Lukas Dirnberger
commited on
Commit
·
c48d412
0
Parent(s):
added dataset card and Builder
Browse files- README.md +0 -0
- dropjects_real.py +175 -0
README.md
ADDED
The diff for this file is too large to render.
See raw diff
|
|
dropjects_real.py
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 Real dataset was created at the Chair of Cyber-Physical Systems in Production \
|
9 |
+
Engineering at the Technical University of Munich.
|
10 |
+
"""
|
11 |
+
|
12 |
+
|
13 |
+
CLASSES = [
|
14 |
+
"battery_holder",
|
15 |
+
"buckle_socket",
|
16 |
+
"buckle_plug",
|
17 |
+
"chew_toy_big",
|
18 |
+
"cpsduck",
|
19 |
+
"cpsglue_big",
|
20 |
+
"group1",
|
21 |
+
"group2",
|
22 |
+
"nema_holder",
|
23 |
+
"stapler",
|
24 |
+
]
|
25 |
+
|
26 |
+
SCENES = [
|
27 |
+
"box",
|
28 |
+
"array", # but only for group1 and group2, and only uncluttered
|
29 |
+
]
|
30 |
+
|
31 |
+
CLUTTER = [
|
32 |
+
"cluttered",
|
33 |
+
"uncluttered",
|
34 |
+
]
|
35 |
+
|
36 |
+
LIGHTING = [
|
37 |
+
"diffuseRight",
|
38 |
+
"diffuseLeft",
|
39 |
+
"spotRight",
|
40 |
+
"spotLeft",
|
41 |
+
"dark",
|
42 |
+
"normal",
|
43 |
+
]
|
44 |
+
|
45 |
+
NUM_SHARDS = 3
|
46 |
+
|
47 |
+
WILDCARD = "{}"
|
48 |
+
|
49 |
+
|
50 |
+
def is_valid_config(spec):
|
51 |
+
cls, scene, clutter, lighting = spec
|
52 |
+
if scene == "array" and cls not in ["group1", "group2", WILDCARD]:
|
53 |
+
return False
|
54 |
+
|
55 |
+
if scene == "array" and clutter not in ["uncluttered", WILDCARD]:
|
56 |
+
return False
|
57 |
+
return True
|
58 |
+
|
59 |
+
|
60 |
+
# ALL_CONFIGS = list(
|
61 |
+
# it.product(
|
62 |
+
# [WILDCARD] + CLASSES, [WILDCARD] + SCENES, [WILDCARD] + CLUTTER, [WILDCARD] + LIGHTING
|
63 |
+
# )
|
64 |
+
# )
|
65 |
+
ALL_CONFIGS = list(it.product(CLASSES, SCENES, CLUTTER, LIGHTING))
|
66 |
+
ALL_CONFIGS = filter(is_valid_config, ALL_CONFIGS)
|
67 |
+
|
68 |
+
|
69 |
+
BASE_PATH = "https://huggingface.co/datasets/LukasDb/dropjects_real/resolve/main/data/test/{cls}/{scene}/{clutter}/{lighting}/{shard}.tar"
|
70 |
+
|
71 |
+
|
72 |
+
class DropjectsRealConfig(d.BuilderConfig):
|
73 |
+
|
74 |
+
def __init__(self, cls: str, scene: str, clutter: str, lighting: str, **kwargs):
|
75 |
+
name = f"{cls}-{scene}-{clutter}-{lighting}"
|
76 |
+
super().__init__(version=d.Version("1.0.0"), **kwargs, name=name)
|
77 |
+
|
78 |
+
# transform wildcards into concrete lists
|
79 |
+
# this does not respect the validity of the config
|
80 |
+
cls = CLASSES if cls == WILDCARD else [cls]
|
81 |
+
scene = SCENES if scene == WILDCARD else [scene]
|
82 |
+
clutter = CLUTTER if clutter == WILDCARD else [clutter]
|
83 |
+
lighting = LIGHTING if lighting == WILDCARD else [lighting]
|
84 |
+
|
85 |
+
self.cls = cls
|
86 |
+
self.scene = scene
|
87 |
+
self.clutter = clutter
|
88 |
+
self.lighting = lighting
|
89 |
+
|
90 |
+
|
91 |
+
class DropjectsReal(d.GeneratorBasedBuilder):
|
92 |
+
BUILDER_CONFIGS = list(
|
93 |
+
DropjectsRealConfig(cls=cls, scene=scene, clutter=clutter, lighting=lighting)
|
94 |
+
for cls, scene, clutter, lighting in ALL_CONFIGS
|
95 |
+
)
|
96 |
+
|
97 |
+
DEFAULT_CONFIG_NAME = f"{WILDCARD}-{WILDCARD}-{WILDCARD}-{WILDCARD}"
|
98 |
+
|
99 |
+
def _info(self):
|
100 |
+
|
101 |
+
features = d.Features(
|
102 |
+
{
|
103 |
+
"rgb": d.Array3D((1242, 2208, 3), dtype="uint8"),
|
104 |
+
"rgb_R": d.Array3D((1242, 2208, 3), dtype="uint8"),
|
105 |
+
"depth": d.Array2D((1242, 2208), dtype="float32"),
|
106 |
+
"depth_gt": d.Array2D((1242, 2208), dtype="float32"),
|
107 |
+
"mask": d.Array2D((1242, 2208), dtype="int32"),
|
108 |
+
"obj_ids": d.Sequence(d.Value("int32")),
|
109 |
+
"obj_classes": d.Sequence(d.Value("string")),
|
110 |
+
"obj_pos": d.Sequence(d.Sequence(d.Value("float32"))),
|
111 |
+
"obj_rot": d.Sequence(d.Sequence(d.Value("float32"))),
|
112 |
+
"obj_bbox_obj": d.Sequence(d.Sequence(d.Value("int32"))),
|
113 |
+
"obj_bbox_visib": d.Sequence(d.Sequence(d.Value("int32"))),
|
114 |
+
"cam_location": d.Sequence(d.Value("float32")),
|
115 |
+
"cam_rotation": d.Sequence(d.Value("float32")),
|
116 |
+
"cam_matrix": d.Array2D((3, 3), dtype="float32"),
|
117 |
+
"obj_px_count_all": d.Sequence(d.Value("int32")),
|
118 |
+
"obj_px_count_valid": d.Sequence(d.Value("int32")),
|
119 |
+
"obj_px_count_visib": d.Sequence(d.Value("int32")),
|
120 |
+
"obj_visib_fract": d.Sequence(d.Value("float32")),
|
121 |
+
}
|
122 |
+
)
|
123 |
+
return d.DatasetInfo(
|
124 |
+
description=_DESCRIPTION,
|
125 |
+
citation="", # TODO
|
126 |
+
homepage="", # TODO
|
127 |
+
license="cc",
|
128 |
+
features=features,
|
129 |
+
)
|
130 |
+
|
131 |
+
def _split_generators(self, dl_manager):
|
132 |
+
clss = self.config.cls
|
133 |
+
scenes = self.config.scene
|
134 |
+
clutters = self.config.clutter
|
135 |
+
lightings = self.config.lighting
|
136 |
+
|
137 |
+
# wildcards to concrete list can generate invalid configs
|
138 |
+
configs = [c for c in it.product(clss, scenes, clutters, lightings) if is_valid_config(c)]
|
139 |
+
|
140 |
+
archive_paths = [
|
141 |
+
BASE_PATH.format(cls=c, scene=s, clutter=cl, lighting=l, shard=i)
|
142 |
+
for c, s, cl, l in configs
|
143 |
+
for i in range(NUM_SHARDS)
|
144 |
+
]
|
145 |
+
|
146 |
+
downloaded = dl_manager.download(archive_paths)
|
147 |
+
|
148 |
+
return [
|
149 |
+
d.SplitGenerator(
|
150 |
+
name=d.Split.TEST,
|
151 |
+
gen_kwargs={"tars": [dl_manager.iter_archive(d) for d in downloaded]},
|
152 |
+
),
|
153 |
+
]
|
154 |
+
|
155 |
+
def _generate_examples(self, tars):
|
156 |
+
sample = {}
|
157 |
+
id = None
|
158 |
+
|
159 |
+
for tar in tars:
|
160 |
+
for file_path, file_obj in tar:
|
161 |
+
new_id = file_path.split(".")[0]
|
162 |
+
if id is None:
|
163 |
+
id = new_id
|
164 |
+
else:
|
165 |
+
if id != new_id:
|
166 |
+
yield id, sample
|
167 |
+
sample = {}
|
168 |
+
id = new_id
|
169 |
+
|
170 |
+
key = file_path.split(".")[1]
|
171 |
+
|
172 |
+
bytes = io.BytesIO(file_obj.read())
|
173 |
+
value = np.load(bytes, allow_pickle=False)
|
174 |
+
|
175 |
+
sample[key] = value
|