|
1 | | -import pytest |
2 | | -from elevation_mapping_cupy import semantic_map, parameter |
3 | 1 | import cupy as cp |
4 | | -import numpy as np |
| 2 | +import pytest |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +from elevation_mapping_cupy import parameter, semantic_map |
| 6 | + |
| 7 | + |
| 8 | +TEST_DIR = Path(__file__).resolve().parent |
| 9 | +PACKAGE_ROOT = TEST_DIR.parents[2] |
| 10 | +CORE_CONFIG_DIR = PACKAGE_ROOT / "config" / "core" |
| 11 | +WEIGHT_FILE = CORE_CONFIG_DIR / "weights.dat" |
| 12 | +PLUGIN_CONFIG_FILE = CORE_CONFIG_DIR / "plugin_config.yaml" |
5 | 13 |
|
6 | 14 |
|
7 | 15 | @pytest.fixture() |
8 | 16 | def semmap_ex(sem_lay, fusion_alg): |
9 | 17 | p = parameter.Parameter( |
10 | 18 | use_chainer=False, |
11 | | - weight_file="../../../config/weights.dat", |
12 | | - plugin_config_file="../../../config/plugin_config.yaml", |
| 19 | + weight_file=str(WEIGHT_FILE), |
| 20 | + plugin_config_file=str(PLUGIN_CONFIG_FILE), |
13 | 21 | ) |
14 | | - for subs, value in p.subscriber_cfg.items(): |
15 | | - value["channels"] = sem_lay |
16 | | - value["fusion"] = fusion_alg |
| 22 | + # Explicitly map test channels to the requested fusion modes. |
| 23 | + for layer, fusion in zip(sem_lay, fusion_alg): |
| 24 | + p.pointcloud_channel_fusions[layer] = fusion |
17 | 25 | p.update() |
18 | | - e = semantic_map.SemanticMap(p) |
19 | | - return e |
| 26 | + return semantic_map.SemanticMap(p) |
20 | 27 |
|
21 | 28 |
|
22 | 29 | @pytest.mark.parametrize( |
23 | | - "sem_lay, fusion_alg,channels", |
| 30 | + "sem_lay,fusion_alg,channels", |
24 | 31 | [ |
25 | 32 | (["feat_0", "feat_1"], ["average", "average"], ["feat_0"]), |
26 | 33 | (["feat_0", "feat_1"], ["average", "average"], []), |
27 | | - (["feat_0", "feat_1", "rgb"], ["average", "average", "color"], ["rgb", "feat_0"],), |
28 | | - (["feat_0", "feat_1", "rgb"], ["class_average", "average", "color"], ["rgb", "feat_0"],), |
29 | | - (["feat_0", "feat_1", "rgb"], ["class_bayesian", "average", "color"], ["rgb", "feat_0"],), |
30 | | - (["feat_0", "feat_1", "rgb"], ["class_bayesian", "average", "color"], ["rgb", "feat_0", "feat_1"],), |
31 | | - (["feat_0", "feat_1", "rgb"], ["class_bayesian", "class_max", "color"], ["rgb", "feat_0", "feat_1"],), |
32 | | - (["max1", "max2", "rgb"], ["class_max", "class_max", "color"], ["rgb", "max1", "max2"],), |
| 34 | + (["feat_0", "feat_1", "rgb"], ["average", "average", "color"], ["rgb", "feat_0"]), |
| 35 | + (["feat_0", "feat_1", "rgb"], ["class_bayesian", "class_max", "color"], ["rgb", "feat_0", "feat_1"]), |
| 36 | + (["max1", "max2", "rgb"], ["class_max", "class_max", "color"], ["rgb", "max1", "max2"]), |
33 | 37 | ], |
34 | 38 | ) |
35 | | -def test_fusion_of_pcl(semmap_ex, channels): |
36 | | - fusion = semmap_ex.get_fusion_of_pcl(channels=channels) |
37 | | - assert len(fusion) <= len(channels) |
38 | | - assert len(fusion) > 0 or len(channels) == 0 |
| 39 | +def test_get_fusion_current_api(semmap_ex, channels): |
| 40 | + process_channels, fusion = semmap_ex.get_fusion( |
| 41 | + channels=channels, |
| 42 | + channel_fusions=semmap_ex.param.pointcloud_channel_fusions, |
| 43 | + layer_specs=semmap_ex.layer_specs_points, |
| 44 | + ) |
| 45 | + assert len(process_channels) == len(fusion) |
39 | 46 | assert all(isinstance(item, str) for item in fusion) |
40 | 47 |
|
41 | 48 |
|
42 | 49 | @pytest.mark.parametrize( |
43 | | - "sem_lay, fusion_alg", [(["feat_0", "feat_1", "rgb"], ["average", "average", "color"]),], |
| 50 | + "sem_lay,fusion_alg,channels,target_fusion", |
| 51 | + [ |
| 52 | + (["feat_0", "feat_1", "rgb"], ["average", "average", "color"], ["rgb", "feat_0"], "color"), |
| 53 | + (["max1", "max2", "rgb"], ["class_max", "class_max", "color"], ["rgb", "max1", "max2"], "class_max"), |
| 54 | + ], |
44 | 55 | ) |
45 | | -@pytest.mark.parametrize("channels", [["rgb"], ["rgb", "feat_0"], []]) |
46 | | -def test_indices_fusion(semmap_ex, channels, fusion_alg): |
47 | | - pcl_indices, layer_indices = semmap_ex.get_indices_fusion(pcl_channels=channels, fusion_alg=fusion_alg[0]) |
| 56 | +def test_get_indices_fusion_current_api(semmap_ex, channels, target_fusion): |
| 57 | + process_channels, _ = semmap_ex.get_fusion( |
| 58 | + channels=channels, |
| 59 | + channel_fusions=semmap_ex.param.pointcloud_channel_fusions, |
| 60 | + layer_specs=semmap_ex.layer_specs_points, |
| 61 | + ) |
| 62 | + for channel in process_channels: |
| 63 | + if channel not in semmap_ex.layer_names: |
| 64 | + semmap_ex.add_layer(channel) |
| 65 | + |
| 66 | + pcl_indices, layer_indices = semmap_ex.get_indices_fusion( |
| 67 | + pcl_channels=process_channels, |
| 68 | + fusion_alg=target_fusion, |
| 69 | + layer_specs=semmap_ex.layer_specs_points, |
| 70 | + ) |
| 71 | + assert pcl_indices.dtype == cp.int32 |
| 72 | + assert layer_indices.dtype == cp.int32 |
0 commit comments