Skip to content

Commit 8cdfcd9

Browse files
committed
first
1 parent c373769 commit 8cdfcd9

File tree

7 files changed

+117
-12
lines changed

7 files changed

+117
-12
lines changed

elevation_mapping_cupy/config/plugin_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ inpainting:
2626
extra_params:
2727
method: "telea" # telea or ns
2828
# Apply smoothing for inpainted layer
29-
smooth_filter_1:
29+
smooth_filter_1:
3030
type: "smooth_filter"
3131
enable: True
3232
fill_nan: False

elevation_mapping_cupy/config/sensor_parameter.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ subscribers:
44
# fusion: ['average','average']
55
# topic_name: '/elevation_mapping/pointcloud_semantic'
66
front_cam:
7-
channels: ['rgb','feat_0','feat_1','person','grass']
8-
fusion: ['color','average','average','class_average']
7+
channels: []
8+
fusion: []
99
topic_name: '/elvation_mapping/pointcloud_semantic'
10-
semantic_segmentation: True
10+
semantic_segmentation: False
1111
segmentation_model: 'detectron_coco_panoptic_fpn_R_101_3x'
1212
feature_config:
1313
name: 'DINO'
@@ -26,6 +26,7 @@ subscribers:
2626
cam_frame: "zed2i_right_camera_optical_frame"
2727
confidence_topic: "/zed2i/zed_node/confidence/confidence_map"
2828
confidence_threshold: 10
29+
feature_extractor: False
2930

3031

3132

elevation_mapping_cupy/script/elevation_mapping_cupy/plugins/inpainting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __call__(
3838
layer_names: List[str],
3939
plugin_layers: cp.ndarray,
4040
plugin_layer_names: List[str],
41+
**kwargs,
4142
) -> cp.ndarray:
4243
mask = cp.asnumpy((elevation_map[2] < 0.5).astype("uint8"))
4344
if (mask < 1).any():

elevation_mapping_cupy/script/elevation_mapping_cupy/plugins/min_filter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def __call__(
9494
layer_names: List[str],
9595
plugin_layers: cp.ndarray,
9696
plugin_layer_names: List[str],
97+
**kwargs,
9798
) -> cp.ndarray:
9899
self.min_filtered = elevation_map[0].copy()
99100
self.min_filtered_mask = elevation_map[2].copy()

elevation_mapping_cupy/script/elevation_mapping_cupy/plugins/plugin_manager.py

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import inspect
1010
from dataclasses import dataclass
1111
from ruamel.yaml import YAML
12+
from inspect import signature
1213

1314

1415
@dataclass
@@ -38,6 +39,7 @@ def __call__(
3839
layer_names: List[str],
3940
plugin_layers: cp.ndarray,
4041
plugin_layer_names: List[str],
42+
**kwargs,
4143
) -> cp.ndarray:
4244
"""This gets the elevation map data and plugin layers as a cupy array.
4345
@@ -75,9 +77,15 @@ def init(self, plugin_params: List[PluginParams], extra_params: List[Dict]):
7577

7678
self.plugins = []
7779
for param, extra_param in zip(plugin_params, extra_params):
78-
m = importlib.import_module("." + param.name, package="elevation_mapping_cupy.plugins") # -> 'module'
80+
m = importlib.import_module(
81+
"." + param.name, package="elevation_mapping_cupy.plugins"
82+
) # -> 'module'
7983
for name, obj in inspect.getmembers(m):
80-
if inspect.isclass(obj) and issubclass(obj, PluginBase) and name != "PluginBase":
84+
if (
85+
inspect.isclass(obj)
86+
# and issubclass(obj, PluginBase)
87+
and name != "PluginBase"
88+
):
8189
# Add cell_n to params
8290
extra_param["cell_n"] = self.cell_n
8391
self.plugins.append(obj(**extra_param))
@@ -102,6 +110,7 @@ def load_plugin_settings(self, file_path: str):
102110
)
103111
)
104112
extra_params.append(v["extra_params"])
113+
print(plugin_params)
105114
self.init(plugin_params, extra_params)
106115
print("Loaded plugins are ", *self.plugin_names)
107116

@@ -133,10 +142,38 @@ def get_layer_index_with_name(self, name: str) -> int:
133142
print("Error with layer {}: {}".format(name, e))
134143
return None
135144

136-
def update_with_name(self, name: str, elevation_map: cp.ndarray, layer_names: List[str]):
145+
def update_with_name(
146+
self,
147+
name: str,
148+
elevation_map: cp.ndarray,
149+
layer_names: List[str],
150+
semantic_map=None,
151+
transform=None,
152+
):
137153
idx = self.get_layer_index_with_name(name)
138154
if idx is not None:
139-
self.layers[idx] = self.plugins[idx](elevation_map, layer_names, self.layers, self.layer_names)
155+
n_param = len(signature(self.plugins[idx]).parameters)
156+
if n_param == 5:
157+
self.layers[idx] = self.plugins[idx](
158+
elevation_map, layer_names, self.layers, self.layer_names
159+
)
160+
elif n_param == 6:
161+
self.layers[idx] = self.plugins[idx](
162+
elevation_map,
163+
layer_names,
164+
self.layers,
165+
self.layer_names,
166+
semantic_map,
167+
)
168+
else:
169+
self.layers[idx] = self.plugins[idx](
170+
elevation_map,
171+
layer_names,
172+
self.layers,
173+
self.layer_names,
174+
semantic_map,
175+
transform,
176+
)
140177

141178
def get_map_with_name(self, name: str) -> cp.ndarray:
142179
idx = self.get_layer_index_with_name(name)
@@ -154,17 +191,28 @@ def get_param_with_name(self, name: str) -> PluginParams:
154191
PluginParams(name="min_filter", layer_name="min_filter"),
155192
PluginParams(name="smooth_filter", layer_name="smooth"),
156193
]
157-
extra_params = [{"dilation_size": 5, "iteration_n": 5}, {"input_layer_name": "elevation2"}]
194+
extra_params = [
195+
{"dilation_size": 5, "iteration_n": 5},
196+
{"input_layer_name": "elevation2"},
197+
]
158198
manager = PluginManager(200)
159-
manager.load_plugin_settings("config/plugin_config.yaml")
199+
manager.load_plugin_settings("../config/plugin_config.yaml")
160200
print(manager.layer_names)
161201
print(manager.plugin_names)
162202
elevation_map = cp.zeros((7, 200, 200)).astype(cp.float32)
163-
layer_names = ["elevation", "variance", "is_valid", "traversability", "time", "upper_bound", "is_upper_bound"]
203+
layer_names = [
204+
"elevation",
205+
"variance",
206+
"is_valid",
207+
"traversability",
208+
"time",
209+
"upper_bound",
210+
"is_upper_bound",
211+
]
164212
elevation_map[0] = cp.random.randn(200, 200)
165213
elevation_map[2] = cp.abs(cp.random.randn(200, 200))
166214
print("map", elevation_map[0])
167215
print("layer map ", manager.layers[0])
168216
manager.update_with_name("min_filter", elevation_map, layer_names)
169-
manager.update_with_name("smooth_filter", elevation_map, layer_names)
217+
manager.update_with_name("smooth", elevation_map, layer_names)
170218
print(manager.get_map_with_name("smooth"))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#
2+
# Copyright (c) 2022, Takahiro Miki. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for details.
4+
#
5+
import cupy as cp
6+
from typing import List
7+
import cupyx.scipy.ndimage as ndimage
8+
9+
from .plugin_manager import PluginBase
10+
from elevation_mapping_cupy.semantic_map import SemanticMap
11+
12+
class SemanticFilter(PluginBase):
13+
"""This is a filter to create colors
14+
15+
...
16+
17+
Attributes
18+
----------
19+
cell_n: int
20+
width and height of the elevation map.
21+
"""
22+
23+
def __init__(self, cell_n: int = 100, input_layer_name: str = "elevation", **kwargs):
24+
super().__init__()
25+
self.input_layer_name = input_layer_name
26+
self.indices = []
27+
28+
def __call__(
29+
self,
30+
elevation_map: cp.ndarray,
31+
layer_names: List[str],
32+
plugin_layers: cp.ndarray,
33+
plugin_layer_names: List[str],
34+
semantic_map: SemanticMap,
35+
**kwargs,
36+
) -> cp.ndarray:
37+
# get indices of all layers that
38+
semantic_map.param.additional_layers
39+
# check which has the highest value
40+
# create color coding
41+
##################
42+
if self.input_layer_name in layer_names:
43+
idx = layer_names.index(self.input_layer_name)
44+
h = elevation_map[idx]
45+
elif self.input_layer_name in plugin_layer_names:
46+
idx = plugin_layer_names.index(self.input_layer_name)
47+
h = plugin_layers[idx]
48+
else:
49+
print("layer name {} was not found. Using elevation layer.".format(self.input_layer_name))
50+
h = elevation_map[0]
51+
hs1 = ndimage.uniform_filter(h, size=3)
52+
hs1 = ndimage.uniform_filter(hs1, size=3)
53+
return hs1

elevation_mapping_cupy/script/elevation_mapping_cupy/plugins/smooth_filter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __call__(
3030
layer_names: List[str],
3131
plugin_layers: cp.ndarray,
3232
plugin_layer_names: List[str],
33+
**kwargs,
3334
) -> cp.ndarray:
3435
if self.input_layer_name in layer_names:
3536
idx = layer_names.index(self.input_layer_name)

0 commit comments

Comments
 (0)