upgrade to vre 1.9.0
Browse files
scripts/dronescapes_viewer/dronescapes_representations.py
CHANGED
@@ -1,19 +1,20 @@
|
|
1 |
import sys
|
2 |
from pathlib import Path
|
3 |
from vre.representations import Representation
|
4 |
-
from
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from
|
9 |
-
from
|
|
|
10 |
|
11 |
def get_gt_tasks() -> dict[str, Representation]:
|
12 |
color_map = [[0, 255, 0], [0, 127, 0], [255, 255, 0], [255, 255, 255],
|
13 |
[255, 0, 0], [0, 0, 255], [0, 255, 255], [127, 127, 63]]
|
14 |
classes_8 = ["land", "forest", "residential", "road", "little-objects", "water", "sky", "hill"]
|
15 |
tasks = [
|
16 |
-
SemanticRepresentation("semantic_output", classes=classes_8, color_map=color_map,
|
17 |
DepthRepresentation("depth_output", min_depth=0, max_depth=300),
|
18 |
NormalsRepresentation("camera_normals_output"),
|
19 |
]
|
|
|
1 |
import sys
|
2 |
from pathlib import Path
|
3 |
from vre.representations import Representation
|
4 |
+
from vre_repository.color.rgb import RGB
|
5 |
+
from vre_repository.color.hsv import HSV
|
6 |
+
from vre_repository.depth import DepthRepresentation
|
7 |
+
from vre_repository.normals import NormalsRepresentation
|
8 |
+
from vre_repository.edges import EdgesRepresentation
|
9 |
+
# from vre_repository.optical_flow import OpticalFlowRepresentation
|
10 |
+
from vre_repository.semantic_segmentation import SemanticRepresentation
|
11 |
|
12 |
def get_gt_tasks() -> dict[str, Representation]:
|
13 |
color_map = [[0, 255, 0], [0, 127, 0], [255, 255, 0], [255, 255, 255],
|
14 |
[255, 0, 0], [0, 0, 255], [0, 255, 255], [127, 127, 63]]
|
15 |
classes_8 = ["land", "forest", "residential", "road", "little-objects", "water", "sky", "hill"]
|
16 |
tasks = [
|
17 |
+
SemanticRepresentation("semantic_output", classes=classes_8, color_map=color_map, disk_data_argmax=True),
|
18 |
DepthRepresentation("depth_output", min_depth=0, max_depth=300),
|
19 |
NormalsRepresentation("camera_normals_output"),
|
20 |
]
|
scripts/semantic_mapper/semantic_mapper.py
CHANGED
@@ -12,9 +12,10 @@ from vre.utils import (semantic_mapper, colorize_semantic_segmentation, DiskData
|
|
12 |
from vre.logger import vre_logger as logger
|
13 |
from vre.readers.multitask_dataset import MultiTaskDataset, MultiTaskItem
|
14 |
from vre.representations import TaskMapper, NpIORepresentation, Representation, build_representations_from_cfg
|
15 |
-
from
|
16 |
-
from
|
17 |
-
from
|
|
|
18 |
|
19 |
def plot_one(data: MultiTaskItem, title: str, order: list[str] | None,
|
20 |
name_to_task: dict[str, Representation]) -> np.ndarray:
|
@@ -97,11 +98,11 @@ mapillary_color_map = [[165, 42, 42], [0, 192, 0], [196, 196, 196], [190, 153, 1
|
|
97 |
[0, 0, 70], [0, 0, 192], [32, 32, 32], [120, 10, 10]]
|
98 |
|
99 |
m2f_coco = SemanticRepresentation("semantic_mask2former_coco_47429163_0", classes=coco_classes,
|
100 |
-
color_map=coco_color_map,
|
101 |
m2f_mapillary = SemanticRepresentation("semantic_mask2former_mapillary_49189528_0", classes=mapillary_classes,
|
102 |
-
color_map=mapillary_color_map,
|
103 |
m2f_r50_mapillary = SemanticRepresentation("semantic_mask2former_mapillary_49189528_1", classes=mapillary_classes,
|
104 |
-
color_map=mapillary_color_map,
|
105 |
marigold = DepthRepresentation("depth_marigold", min_depth=0, max_depth=1)
|
106 |
normals_svd_marigold = NormalsRepresentation("normals_svd(depth_marigold)")
|
107 |
|
@@ -145,8 +146,7 @@ class SemanticMask2FormerMapillaryConvertedPaper(TaskMapper, NpIORepresentation)
|
|
145 |
|
146 |
@overrides
|
147 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
148 |
-
|
149 |
-
m2f_mapillary_converted = semantic_mapper(m2f_mapillary, self.mapping, self.original_classes)
|
150 |
return self.disk_to_memory_fmt(m2f_mapillary_converted)
|
151 |
|
152 |
@overrides
|
@@ -204,8 +204,7 @@ class SemanticMask2FormerCOCOConverted(TaskMapper, NpIORepresentation):
|
|
204 |
|
205 |
@overrides
|
206 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
207 |
-
|
208 |
-
m2f_mapillary_converted = semantic_mapper(m2f_mapillary, self.mapping, self.original_classes)
|
209 |
res = self.disk_to_memory_fmt(m2f_mapillary_converted)
|
210 |
return res
|
211 |
|
@@ -258,10 +257,7 @@ class BinaryMapper(TaskMapper, NpIORepresentation):
|
|
258 |
|
259 |
@overrides
|
260 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
261 |
-
dep_data_argmaxed = []
|
262 |
-
for dep, data in zip(self.dependencies, dep_data):
|
263 |
-
assert isinstance(dep, SemanticRepresentation), type(dep)
|
264 |
-
dep_data_argmaxed.append(dep.to_argmaxed_representation(data))
|
265 |
dep_data_converted = [semantic_mapper(x, mapping, oc)
|
266 |
for x, mapping, oc in zip(dep_data_argmaxed, self.mapping, self.original_classes)]
|
267 |
|
@@ -304,13 +300,9 @@ class SemanticMedian(TaskMapper, NpIORepresentation):
|
|
304 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
305 |
return MemoryData(np.eye(self.n_classes)[sum(dep_data).argmax(-1)].astype(np.uint8))
|
306 |
|
307 |
-
@overrides
|
308 |
-
def memory_to_disk_fmt(self, memory_data: MemoryData) -> DiskData:
|
309 |
-
return memory_data.argmax(-1).astype(np.uint8)
|
310 |
-
|
311 |
@overrides
|
312 |
def make_images(self, data: ReprOut) -> np.ndarray:
|
313 |
-
data_output = data.output.argmax(-1)
|
314 |
return colorize_semantic_segmentation(data_output, self.classes, self.color_map)
|
315 |
|
316 |
class SafeLandingAreas(BinaryMapper, NpIORepresentation):
|
@@ -355,12 +347,9 @@ class SafeLandingAreas(BinaryMapper, NpIORepresentation):
|
|
355 |
v1, v2, v3 = normals.transpose(2, 0, 1)
|
356 |
where_safe = (v2 > 0.8) * ((v1 + v3) < 1.2) * (depth <= 0.9)
|
357 |
if self.include_semantics:
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
conv1 = np.isin(mapi1, self.safe_mapillary_ix).astype(int)
|
362 |
-
conv2 = np.isin(coco, self.safe_coco_ix).astype(int)
|
363 |
-
conv3 = np.isin(mapi2, self.safe_mapillary_ix).astype(int)
|
364 |
sema_safe = (conv1 + conv2 + conv3) >= 2
|
365 |
where_safe = sema_safe * where_safe
|
366 |
return self.disk_to_memory_fmt(where_safe)
|
@@ -500,22 +489,20 @@ def get_new_semantic_mapped_tasks(tasks_subset: list[str] | None = None) -> dict
|
|
500 |
return {t.name: t for t in available_tasks if t.name in tasks_subset}
|
501 |
|
502 |
if __name__ == "__main__":
|
503 |
-
cfg_path = Path.cwd() / "
|
504 |
-
data_path = Path.cwd() / "
|
505 |
vre_dir = data_path
|
506 |
|
507 |
task_names = ["rgb", "depth_marigold", "normals_svd(depth_marigold)",
|
508 |
-
"semantic_mask2former_coco_47429163_0", "semantic_mask2former_mapillary_49189528_0"
|
509 |
-
"semantic_mask2former_mapillary_49189528_1"]
|
510 |
order = ["rgb", "semantic_mask2former_mapillary_49189528_0", "semantic_mask2former_coco_47429163_0",
|
511 |
"depth_marigold", "normals_svd(depth_marigold)"]
|
512 |
|
513 |
-
|
514 |
-
|
515 |
-
# breakpoint()
|
516 |
reader = MultiTaskDataset(vre_dir, task_names=task_names, task_types=task_types,
|
517 |
-
handle_missing_data="fill_nan", normalization=
|
518 |
-
cache_task_stats=True, batch_size_stats=100
|
519 |
orig_task_names = list(reader.task_types.keys())
|
520 |
|
521 |
new_tasks = get_new_semantic_mapped_tasks()
|
|
|
12 |
from vre.logger import vre_logger as logger
|
13 |
from vre.readers.multitask_dataset import MultiTaskDataset, MultiTaskItem
|
14 |
from vre.representations import TaskMapper, NpIORepresentation, Representation, build_representations_from_cfg
|
15 |
+
from vre_repository import get_vre_repository
|
16 |
+
from vre_repository.depth import DepthRepresentation
|
17 |
+
from vre_repository.normals import NormalsRepresentation
|
18 |
+
from vre_repository.semantic_segmentation import SemanticRepresentation
|
19 |
|
20 |
def plot_one(data: MultiTaskItem, title: str, order: list[str] | None,
|
21 |
name_to_task: dict[str, Representation]) -> np.ndarray:
|
|
|
98 |
[0, 0, 70], [0, 0, 192], [32, 32, 32], [120, 10, 10]]
|
99 |
|
100 |
m2f_coco = SemanticRepresentation("semantic_mask2former_coco_47429163_0", classes=coco_classes,
|
101 |
+
color_map=coco_color_map, disk_data_argmax=True)
|
102 |
m2f_mapillary = SemanticRepresentation("semantic_mask2former_mapillary_49189528_0", classes=mapillary_classes,
|
103 |
+
color_map=mapillary_color_map, disk_data_argmax=True)
|
104 |
m2f_r50_mapillary = SemanticRepresentation("semantic_mask2former_mapillary_49189528_1", classes=mapillary_classes,
|
105 |
+
color_map=mapillary_color_map, disk_data_argmax=True)
|
106 |
marigold = DepthRepresentation("depth_marigold", min_depth=0, max_depth=1)
|
107 |
normals_svd_marigold = NormalsRepresentation("normals_svd(depth_marigold)")
|
108 |
|
|
|
146 |
|
147 |
@overrides
|
148 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
149 |
+
m2f_mapillary_converted = semantic_mapper(dep_data[0].argmax(-1), self.mapping, self.original_classes)
|
|
|
150 |
return self.disk_to_memory_fmt(m2f_mapillary_converted)
|
151 |
|
152 |
@overrides
|
|
|
204 |
|
205 |
@overrides
|
206 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
207 |
+
m2f_mapillary_converted = semantic_mapper(dep_data[0].argmax(-1), self.mapping, self.original_classes)
|
|
|
208 |
res = self.disk_to_memory_fmt(m2f_mapillary_converted)
|
209 |
return res
|
210 |
|
|
|
257 |
|
258 |
@overrides
|
259 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
260 |
+
dep_data_argmaxed = [data.argmax(-1) for data in dep_data]
|
|
|
|
|
|
|
261 |
dep_data_converted = [semantic_mapper(x, mapping, oc)
|
262 |
for x, mapping, oc in zip(dep_data_argmaxed, self.mapping, self.original_classes)]
|
263 |
|
|
|
300 |
def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
|
301 |
return MemoryData(np.eye(self.n_classes)[sum(dep_data).argmax(-1)].astype(np.uint8))
|
302 |
|
|
|
|
|
|
|
|
|
303 |
@overrides
|
304 |
def make_images(self, data: ReprOut) -> np.ndarray:
|
305 |
+
data_output = data.output.argmax(-1) if np.issubdtype(data.output.dtype, np.floating) else data.output
|
306 |
return colorize_semantic_segmentation(data_output, self.classes, self.color_map)
|
307 |
|
308 |
class SafeLandingAreas(BinaryMapper, NpIORepresentation):
|
|
|
347 |
v1, v2, v3 = normals.transpose(2, 0, 1)
|
348 |
where_safe = (v2 > 0.8) * ((v1 + v3) < 1.2) * (depth <= 0.9)
|
349 |
if self.include_semantics:
|
350 |
+
conv1 = np.isin(dep_data[2].argmax(-1), self.safe_mapillary_ix).astype(int)
|
351 |
+
conv2 = np.isin(dep_data[3].argmax(-1), self.safe_coco_ix).astype(int)
|
352 |
+
conv3 = np.isin(dep_data[4].argmax(-1), self.safe_mapillary_ix).astype(int)
|
|
|
|
|
|
|
353 |
sema_safe = (conv1 + conv2 + conv3) >= 2
|
354 |
where_safe = sema_safe * where_safe
|
355 |
return self.disk_to_memory_fmt(where_safe)
|
|
|
489 |
return {t.name: t for t in available_tasks if t.name in tasks_subset}
|
490 |
|
491 |
if __name__ == "__main__":
|
492 |
+
cfg_path = Path.cwd() / "cfg.yaml"
|
493 |
+
data_path = Path.cwd() / "data"
|
494 |
vre_dir = data_path
|
495 |
|
496 |
task_names = ["rgb", "depth_marigold", "normals_svd(depth_marigold)",
|
497 |
+
"semantic_mask2former_coco_47429163_0", "semantic_mask2former_mapillary_49189528_0"]
|
|
|
498 |
order = ["rgb", "semantic_mask2former_mapillary_49189528_0", "semantic_mask2former_coco_47429163_0",
|
499 |
"depth_marigold", "normals_svd(depth_marigold)"]
|
500 |
|
501 |
+
repr_types = get_vre_repository()
|
502 |
+
task_types = {r.name: r for r in build_representations_from_cfg(cfg_path, repr_types) if r.name in task_names}
|
|
|
503 |
reader = MultiTaskDataset(vre_dir, task_names=task_names, task_types=task_types,
|
504 |
+
handle_missing_data="fill_nan", normalization=None,
|
505 |
+
cache_task_stats=True, batch_size_stats=100)
|
506 |
orig_task_names = list(reader.task_types.keys())
|
507 |
|
508 |
new_tasks = get_new_semantic_mapped_tasks()
|
vre_dronescapes/cfg.yaml
CHANGED
@@ -12,7 +12,7 @@ default_compute_parameters:
|
|
12 |
|
13 |
representations:
|
14 |
rgb:
|
15 |
-
type:
|
16 |
dependencies: []
|
17 |
parameters: {}
|
18 |
|
@@ -30,7 +30,7 @@ representations:
|
|
30 |
dependencies: []
|
31 |
parameters:
|
32 |
model_id: "47429163_0"
|
33 |
-
|
34 |
compute_parameters:
|
35 |
batch_size: 1
|
36 |
|
@@ -39,7 +39,7 @@ representations:
|
|
39 |
dependencies: []
|
40 |
parameters:
|
41 |
model_id: "49189528_0"
|
42 |
-
|
43 |
compute_parameters:
|
44 |
batch_size: 1
|
45 |
|
@@ -48,7 +48,7 @@ representations:
|
|
48 |
dependencies: []
|
49 |
parameters:
|
50 |
model_id: "49189528_1"
|
51 |
-
|
52 |
compute_parameters:
|
53 |
batch_size: 1
|
54 |
|
|
|
12 |
|
13 |
representations:
|
14 |
rgb:
|
15 |
+
type: color/rgb
|
16 |
dependencies: []
|
17 |
parameters: {}
|
18 |
|
|
|
30 |
dependencies: []
|
31 |
parameters:
|
32 |
model_id: "47429163_0"
|
33 |
+
disk_data_argmax: True
|
34 |
compute_parameters:
|
35 |
batch_size: 1
|
36 |
|
|
|
39 |
dependencies: []
|
40 |
parameters:
|
41 |
model_id: "49189528_0"
|
42 |
+
disk_data_argmax: True
|
43 |
compute_parameters:
|
44 |
batch_size: 1
|
45 |
|
|
|
48 |
dependencies: []
|
49 |
parameters:
|
50 |
model_id: "49189528_1"
|
51 |
+
disk_data_argmax: True
|
52 |
compute_parameters:
|
53 |
batch_size: 1
|
54 |
|