Skip to content

Commit 5652a44

Browse files
fix: slight change to autolabels and support for pd (#92)
* fix: slight change to autolabels and exposed to pd
1 parent 21bbe8d commit 5652a44

File tree

3 files changed

+66
-14
lines changed

3 files changed

+66
-14
lines changed

dgp/datasets/base_dataset.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,11 @@ def _get_scene_container(
10071007
if requested_autolabels is not None:
10081008
logging.debug(f"Loading autolabeled annotations from {scene_dir}.")
10091009
autolabeled_scenes = _parse_autolabeled_scenes(
1010-
scene_dir, requested_autolabels, autolabel_root=autolabel_root, skip_missing_data=skip_missing_data
1010+
scene_dir,
1011+
requested_autolabels,
1012+
autolabel_root=autolabel_root,
1013+
skip_missing_data=skip_missing_data,
1014+
use_diskcache=use_diskcache,
10111015
)
10121016
else:
10131017
autolabeled_scenes = None
@@ -1381,21 +1385,24 @@ def load_annotations(self, scene_idx, sample_idx_in_scene, datum_name):
13811385
autolabel_annotations = self.get_autolabels_for_datum(scene_idx, sample_idx_in_scene, datum_name)
13821386
for autolabel_key in self.requested_autolabels:
13831387
# Some datums in a sample may not have associated annotations. Return "None" for those datums
1384-
_, annotation_key = autolabel_key.split('/')
1385-
# NOTE: model_name should already be stored in the scene json
1386-
# which is why we do not have to add it here to the annotation_file
1388+
model_name, annotation_key = autolabel_key.split('/')
1389+
# NOTE: model_name should typically not be included in the annotation_path stored inside the scene.json
1390+
# if for some reason it is, then it needs to be removed.
1391+
13871392
annotation_path = autolabel_annotations.get(autolabel_key, None)
13881393

13891394
if annotation_path is None:
13901395
autolabel_annotations[autolabel_key] = None
13911396
continue
13921397
if self.autolabel_root is not None:
13931398
annotation_file = os.path.join(
1394-
self.autolabel_root, os.path.basename(self.scenes[scene_idx].directory), 'autolabels',
1395-
annotation_path
1399+
self.autolabel_root, os.path.basename(self.scenes[scene_idx].directory), AUTOLABEL_FOLDER,
1400+
model_name, annotation_path
13961401
)
13971402
else:
1398-
annotation_file = os.path.join(self.scenes[scene_idx].directory, 'autolabels', annotation_path)
1403+
annotation_file = os.path.join(
1404+
self.scenes[scene_idx].directory, AUTOLABEL_FOLDER, model_name, annotation_path
1405+
)
13991406

14001407
if not os.path.exists(annotation_file):
14011408
logging.warning(f'missing {annotation_file}')
@@ -1835,7 +1842,13 @@ def get_file_meta_from_datum(self, scene_idx, sample_idx_in_scene, datum_name):
18351842
return data, annotations
18361843

18371844

1838-
def _parse_autolabeled_scenes(scene_dir, requested_autolabels, autolabel_root=None, skip_missing_data=False):
1845+
def _parse_autolabeled_scenes(
1846+
scene_dir,
1847+
requested_autolabels,
1848+
autolabel_root=None,
1849+
skip_missing_data=False,
1850+
use_diskcache=False,
1851+
):
18391852
"""Parse autolabeled scene JSONs
18401853
18411854
Parameters
@@ -1852,6 +1865,9 @@ def _parse_autolabeled_scenes(scene_dir, requested_autolabels, autolabel_root=No
18521865
skip_missing_data: bool, defaul: False
18531866
If true, skip over missing autolabel scenes
18541867
1868+
use_diskcache: bool, default: False
1869+
If diskcache should be used for autolabels
1870+
18551871
Returns
18561872
-------
18571873
autolabeled_scenes: dict
@@ -1883,5 +1899,7 @@ def _parse_autolabeled_scenes(scene_dir, requested_autolabels, autolabel_root=No
18831899
assert os.path.exists(autolabel_dir), 'Path to autolabels {} does not exist'.format(autolabel_dir)
18841900
assert os.path.exists(autolabel_scene), 'Scene JSON expected but not found at {}'.format(autolabel_scene)
18851901

1886-
autolabeled_scenes[autolabel] = SceneContainer(autolabel_scene, directory=autolabel_dir)
1902+
autolabeled_scenes[autolabel] = SceneContainer(
1903+
autolabel_scene, directory=autolabel_dir, use_diskcache=use_diskcache
1904+
)
18871905
return autolabeled_scenes

dgp/datasets/pd_dataset.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class _ParallelDomainDataset(_SynchronizedDataset):
8383
8484
transform_accumulated_box_points: bool, default: False
8585
Flag to use cuboid pose and instance id to warp points when using lidar accumulation.
86+
87+
autolabel_root: str, default: None
88+
Path to autolabels.
8689
"""
8790
def __init__(
8891
self,
@@ -98,6 +101,7 @@ def __init__(
98101
use_virtual_camera_datums=True,
99102
accumulation_context=None,
100103
transform_accumulated_box_points=False,
104+
autolabel_root=None,
101105
):
102106
self.coalesce_point_cloud = datum_names is not None and \
103107
COALESCED_LIDAR_DATUM_NAME in datum_names
@@ -136,6 +140,7 @@ def __init__(
136140
only_annotated_datums=only_annotated_datums,
137141
accumulation_context=accumulation_context,
138142
transform_accumulated_box_points=transform_accumulated_box_points,
143+
autolabel_root=autolabel_root,
139144
)
140145

141146
def coalesce_pc_data(self, items):
@@ -155,6 +160,12 @@ def coalesce_pc_data(self, items):
155160
assert self.coalesce_point_cloud
156161
assert len(pc_items) == len(LIDAR_DATUM_NAMES)
157162

163+
# TODO: fix this
164+
if len(self.requested_autolabels) > 0:
165+
logging.warning(
166+
'autolabels were requested, however point cloud coalesce does not support coalescing autolabels'
167+
)
168+
158169
# Only coalesce if there's more than 1 point cloud
159170
coalesced_pc = OrderedDict()
160171
X_V_merged, bbox_3d_V_merged, instance_ids_merged = [], [], []
@@ -248,6 +259,7 @@ def __init__(
248259
dataset_root=None,
249260
transform_accumulated_box_points=False,
250261
use_diskcache=True,
262+
autolabel_root=None,
251263
):
252264
if not use_diskcache:
253265
logging.warning('Instantiating a dataset with use_diskcache=False may exhaust memory with a large dataset.')
@@ -261,10 +273,16 @@ def __init__(
261273
skip_missing_data=skip_missing_data,
262274
dataset_root=dataset_root,
263275
use_diskcache=use_diskcache,
276+
autolabel_root=autolabel_root,
264277
)
265278

266279
# Return SynchronizedDataset with scenes built from dataset.json
267-
dataset_metadata = DatasetMetadata.from_scene_containers(scenes, requested_annotations, requested_autolabels)
280+
dataset_metadata = DatasetMetadata.from_scene_containers(
281+
scenes,
282+
requested_annotations,
283+
requested_autolabels,
284+
autolabel_root=autolabel_root,
285+
)
268286
super().__init__(
269287
dataset_metadata,
270288
scenes=scenes,
@@ -278,6 +296,7 @@ def __init__(
278296
use_virtual_camera_datums=use_virtual_camera_datums,
279297
accumulation_context=accumulation_context,
280298
transform_accumulated_box_points=transform_accumulated_box_points,
299+
autolabel_root=autolabel_root,
281300
)
282301

283302

@@ -300,6 +319,7 @@ def __init__(
300319
accumulation_context=None,
301320
transform_accumulated_box_points=False,
302321
use_diskcache=True,
322+
autolabel_root=None,
303323
):
304324
if not use_diskcache:
305325
logging.warning('Instantiating a dataset with use_diskcache=False may exhaust memory with a large dataset.')
@@ -311,10 +331,16 @@ def __init__(
311331
is_datums_synchronized=True,
312332
skip_missing_data=skip_missing_data,
313333
use_diskcache=use_diskcache,
334+
autolabel_root=autolabel_root,
314335
)
315336

316337
# Return SynchronizedDataset with scenes built from dataset.json
317-
dataset_metadata = DatasetMetadata.from_scene_containers([scene], requested_annotations, requested_autolabels)
338+
dataset_metadata = DatasetMetadata.from_scene_containers(
339+
[scene],
340+
requested_annotations,
341+
requested_autolabels,
342+
autolabel_root=autolabel_root,
343+
)
318344
super().__init__(
319345
dataset_metadata,
320346
scenes=[scene],

tests/test_autolabel_dataset.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ def clone_scene_as_autolabel(dataset_root, autolabel_root, autolabel_model, auto
6262
if 'scene' in scene_json and scene_json.endswith('json'):
6363
base_scene = open_pbobject(os.path.join(full_scene_dir, scene_json), Scene)
6464
for i in range(len(base_scene.data)):
65+
name = base_scene.data[i].id.name
6566
datum = base_scene.data[i].datum
6667
datum_type = datum.WhichOneof('datum_oneof')
6768
datum_value = getattr(datum, datum_type) # This is datum.image or datum.point_cloud etc
6869
annotation_type_id = ANNOTATION_KEY_TO_TYPE_ID[autolabel_type]
6970
current_annotation = datum_value.annotations[annotation_type_id]
70-
datum_value.annotations[annotation_type_id] = os.path.join(autolabel_scene_dir, current_annotation)
71+
# NOTE: this should not actually change the path but is included for clarity
72+
datum_value.annotations[annotation_type_id] = os.path.join(
73+
ANNOTATION_TYPE_ID_TO_FOLDER[autolabel_type], name, os.path.basename(current_annotation)
74+
)
7175

7276
save_pbobject_as_json(base_scene, os.path.join(autolabel_scene_dir, AUTOLABEL_SCENE_JSON_NAME))
7377
# Only modify one scene.json, test scene should not contain multiple scene.jsons
@@ -109,7 +113,8 @@ def test_autolabels_default_root(self):
109113
backward_context=1,
110114
requested_annotations=('bounding_box_3d', ),
111115
requested_autolabels=requested_autolabels,
112-
autolabel_root=autolabel_root
116+
autolabel_root=autolabel_root,
117+
use_diskcache=False,
113118
)
114119

115120
assert len(dataset) == 2
@@ -139,7 +144,8 @@ def test_autolabels_custom_root(self):
139144
backward_context=1,
140145
requested_annotations=('bounding_box_3d', ),
141146
requested_autolabels=requested_autolabels,
142-
autolabel_root=autolabel_root
147+
autolabel_root=autolabel_root,
148+
use_diskcache=False,
143149
)
144150

145151
assert len(dataset) == 2
@@ -174,6 +180,7 @@ def test_autolabels_missing_files(self):
174180
requested_autolabels=requested_autolabels,
175181
autolabel_root=autolabel_root,
176182
skip_missing_data=True,
183+
use_diskcache=False,
177184
)
178185

179186
assert len(dataset) == 2
@@ -210,6 +217,7 @@ def test_only_annotated_datums(self):
210217
autolabel_root=autolabel_root,
211218
only_annotated_datums=True,
212219
skip_missing_data=True,
220+
use_diskcache=False,
213221
)
214222

215223
assert len(dataset) == 1

0 commit comments

Comments
 (0)