updates to depth representation
Browse files
dronescapes_reader/dronescapes_representations.py
CHANGED
@@ -30,13 +30,22 @@ class EdgesRepresentation(NpzRepresentation):
|
|
30 |
|
31 |
class DepthRepresentation(NpzRepresentation):
|
32 |
"""DepthRepresentation. Implements depth task-specific stuff, like hotmap."""
|
33 |
-
def __init__(self, name: str):
|
34 |
super().__init__(name, n_channels=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
@overrides
|
37 |
def plot_fn(self, x: tr.Tensor) -> np.ndarray:
|
38 |
x = x.detach().clip(0, 1).squeeze().cpu().numpy()
|
39 |
-
_min, _max = np.percentile(x, [
|
40 |
x = np.nan_to_num((x - _min) / (_max - _min), False, 0, 0, 0).clip(0, 1)
|
41 |
y: np.ndarray = hot(x)[..., 0:3] * 255
|
42 |
return y.astype(np.uint8)
|
@@ -91,9 +100,9 @@ dronescapes_task_types = { # some pre-baked representations
|
|
91 |
"hsv": HSVRepresentation("hsv"),
|
92 |
"edges_dexined": EdgesRepresentation("edges_dexined"),
|
93 |
"edges_gb": EdgesRepresentation("edges_gb"),
|
94 |
-
"depth_dpt": DepthRepresentation("depth_dpt"),
|
95 |
-
"depth_sfm_manual202204": DepthRepresentation("depth_sfm_manual202204"),
|
96 |
-
"depth_ufo": DepthRepresentation("depth_ufo"),
|
97 |
"normals_sfm_manual202204": NormalsRepresentation("normals_sfm_manual202204"),
|
98 |
"opticalflow_rife": OpticalFlowRepresentation("opticalflow_rife"),
|
99 |
"semantic_segprop8": SemanticRepresentation("semantic_segprop8", classes=8, color_map=_color_map),
|
|
|
30 |
|
31 |
class DepthRepresentation(NpzRepresentation):
|
32 |
"""DepthRepresentation. Implements depth task-specific stuff, like hotmap."""
|
33 |
+
def __init__(self, name: str, min_depth: float, max_depth: float):
|
34 |
super().__init__(name, n_channels=1)
|
35 |
+
self.min_depth = min_depth
|
36 |
+
self.max_depth = max_depth
|
37 |
+
|
38 |
+
@overrides
|
39 |
+
def load_from_disk(self, path: Path) -> tr.Tensor:
|
40 |
+
"""Reads the npz data from the disk and transforms it properly"""
|
41 |
+
res = super().load_from_disk(path)
|
42 |
+
res_clip = res.clip(self.min_depth, self.max_depth)
|
43 |
+
return res_clip
|
44 |
|
45 |
@overrides
|
46 |
def plot_fn(self, x: tr.Tensor) -> np.ndarray:
|
47 |
x = x.detach().clip(0, 1).squeeze().cpu().numpy()
|
48 |
+
_min, _max = np.percentile(x, [1, 95])
|
49 |
x = np.nan_to_num((x - _min) / (_max - _min), False, 0, 0, 0).clip(0, 1)
|
50 |
y: np.ndarray = hot(x)[..., 0:3] * 255
|
51 |
return y.astype(np.uint8)
|
|
|
100 |
"hsv": HSVRepresentation("hsv"),
|
101 |
"edges_dexined": EdgesRepresentation("edges_dexined"),
|
102 |
"edges_gb": EdgesRepresentation("edges_gb"),
|
103 |
+
"depth_dpt": DepthRepresentation("depth_dpt", min_depth=0, max_depth=0.999),
|
104 |
+
"depth_sfm_manual202204": DepthRepresentation("depth_sfm_manual202204", min_depth=0, max_depth=300),
|
105 |
+
"depth_ufo": DepthRepresentation("depth_ufo", min_depth=0, max_depth=1),
|
106 |
"normals_sfm_manual202204": NormalsRepresentation("normals_sfm_manual202204"),
|
107 |
"opticalflow_rife": OpticalFlowRepresentation("opticalflow_rife"),
|
108 |
"semantic_segprop8": SemanticRepresentation("semantic_segprop8", classes=8, color_map=_color_map),
|