Skip to content

Commit

Permalink
Merge branch '900-chaine-low-cost' into 'master'
Browse files Browse the repository at this point in the history
Chaine low cost: sans validation croisée

Closes #900

See merge request 3d/cars-park/cars!748
  • Loading branch information
dyoussef committed Oct 2, 2024
2 parents d1245da + c77d9ee commit a1b00d2
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 8 deletions.
6 changes: 6 additions & 0 deletions cars/applications/dense_matching/census_mccnn_sgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__(self, conf=None):
self.disp_range_propagation_filter_size = self.used_config[
"disp_range_propagation_filter_size"
]
self.use_cross_validation = self.used_config["use_cross_validation"]
# Saving files
self.save_intermediate_data = self.used_config["save_intermediate_data"]

Expand Down Expand Up @@ -171,6 +172,9 @@ def check_conf(self, conf):
overloaded_conf["perf_ambiguity_threshold"] = conf.get(
"perf_ambiguity_threshold", 0.6
)
overloaded_conf["use_cross_validation"] = conf.get(
"use_cross_validation", False
)
# Margins computation parameters
overloaded_conf["use_global_disp_range"] = conf.get(
"use_global_disp_range", False
Expand Down Expand Up @@ -213,6 +217,7 @@ def check_conf(self, conf):
perf_eta_max_ambiguity=overloaded_conf["perf_eta_max_ambiguity"],
perf_eta_max_risk=overloaded_conf["perf_eta_max_risk"],
perf_eta_step=overloaded_conf["perf_eta_step"],
use_cross_validation=overloaded_conf["use_cross_validation"],
)
overloaded_conf["loader"] = loader
overloaded_conf["loader_conf"] = loader_conf
Expand All @@ -237,6 +242,7 @@ def check_conf(self, conf):
"perf_eta_max_risk": float,
"perf_eta_step": float,
"perf_ambiguity_threshold": float,
"use_cross_validation": bool,
"use_global_disp_range": bool,
"local_disp_grid_step": int,
"disp_range_propagation_filter_size": And(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
"filter": {
"filter_method": "median",
"filter_size": 3
},
"validation": {
"validation_method": "cross_checking_accurate",
"cross_checking_threshold": 1.0
}
}
}
4 changes: 0 additions & 4 deletions cars/applications/dense_matching/loaders/config_mccnn.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
"filter" : {
"filter_method": "median",
"filter_size": 3
},
"validation" : {
"validation_method": "cross_checking_accurate",
"cross_checking_threshold": 1
}
}
}
15 changes: 15 additions & 0 deletions cars/applications/dense_matching/loaders/pandora_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__( # noqa: C901
perf_eta_max_ambiguity=0.99,
perf_eta_max_risk=0.25,
perf_eta_step=0.04,
use_cross_validation=False,
):
"""
Init function of PandoraLoader
Expand All @@ -70,8 +71,11 @@ def __init__( # noqa: C901
:type conf: dict
:param method_name: name of method to use
:param performance_map_conf: true if generate performance maps
:param use_cross_validation: true to add crossvalidation
"""
if method_name is None:
method_name = "census_sgm"

self.pandora_config = None

Expand Down Expand Up @@ -141,6 +145,13 @@ def __init__( # noqa: C901
"confidence_method": "interval_bounds",
}
}
# Cross validation
cross_validation_conf = {
"validation": {
"validation_method": "cross_checking_accurate",
"cross_checking_threshold": 1.0,
}
}

confidences = {}
if generate_performance_map:
Expand Down Expand Up @@ -175,6 +186,10 @@ def __init__( # noqa: C901
conf["pipeline"], confidences
)

# update with cross validation
if use_cross_validation and "validation" not in conf["pipeline"]:
conf["pipeline"].update(cross_validation_conf)

if generate_confidence_intervals:
# To ensure the consistency between the disparity map
# and the intervals, the median filter for intervals
Expand Down
6 changes: 6 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,12 @@ The structure follows this organisation:
- should be > 0
- 300
- No
* - use_cross_validation
- Add cross validation step
- bool
-
- false
- No
See `Pandora documentation <https://pandora.readthedocs.io/>`_ for more information.
Expand Down
63 changes: 63 additions & 0 deletions tests/applications/dense_matching/test_pandora_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# Standard imports

# Third party imports
import copy

import pytest

# CARS imports
Expand Down Expand Up @@ -95,6 +97,67 @@ def test_configure_pandora_config():
assert corr_config["pipeline"]["optimization"]["penalty"]["P2"] == 24


@pytest.mark.unit_tests
def test_configure_cross_validation():
"""
Test configure pandora correlator cross validation
"""

pandora_config = {
"input": {"nodata_left": "NaN", "nodata_right": "NaN"},
"pipeline": {
"right_disp_map": {"method": "accurate"},
"matching_cost": {
"matching_cost_method": "census",
"window_size": 5,
"subpix": 1,
},
"optimization": {
"optimization_method": "sgm",
"penalty": {
"P1": 8,
"P2": 24,
"p2_method": "constant",
"penalty_method": "sgm_penalty",
},
"overcounting": False,
"min_cost_paths": False,
},
"disparity": {
"disparity_method": "wta",
"invalid_disparity": "NaN",
},
"refinement": {"refinement_method": "vfit"},
"filter": {"filter_method": "median", "filter_size": 3},
},
}

# test 1, validation as input already
conf_with_validation = copy.deepcopy(pandora_config)
conf_with_validation["pipeline"].update(
{"validation": {"validation_method": "cross_checking"}}
)
pandora_loader = PandoraLoader(
conf=conf_with_validation, use_cross_validation=False
)
corr_config = pandora_loader.get_conf()
assert "validation" in corr_config["pipeline"]

# test 2: no validation as input, add it
pandora_loader = PandoraLoader(
conf=copy.deepcopy(pandora_config), use_cross_validation=True
)
corr_config = pandora_loader.get_conf()
assert "validation" in corr_config["pipeline"]

# test 3: no validation as input, do not add it
pandora_loader = PandoraLoader(
conf=copy.deepcopy(pandora_config), use_cross_validation=False
)
corr_config = pandora_loader.get_conf()
assert "validation" not in corr_config["pipeline"]


@pytest.mark.unit_tests
def test_overload_pandora_conf_with_confidence():
"""
Expand Down
26 changes: 26 additions & 0 deletions tests/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_end2end_gizeh_rectangle_epi_image_performance_map():
"grid_generation": {"method": "epipolar", "epi_step": 30},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": True,
},
"point_cloud_rasterization": {
Expand Down Expand Up @@ -632,6 +633,7 @@ def test_end2end_ventoux_unique():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
"loader_conf": {
"input": {},
Expand Down Expand Up @@ -1029,6 +1031,7 @@ def test_end2end_ventoux_unique():
dense_dsm_applications = {
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"point_cloud_outliers_removing.1": {
Expand Down Expand Up @@ -1102,6 +1105,12 @@ def test_end2end_ventoux_unique_split_epsg_4326():
"max_ram_per_worker": 1000,
},
)
input_config_pc["applications"] = {
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
},
}
pc_pipeline = sensor_to_dense_dsm.SensorToDenseDsmPipeline(
input_config_pc
)
Expand Down Expand Up @@ -1317,6 +1326,7 @@ def test_end2end_ventoux_unique_split():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
"save_intermediate_data": True,
"generate_confidence_intervals": False,
Expand Down Expand Up @@ -2222,6 +2232,7 @@ def test_end2end_use_epipolar_a_priori():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
}
Expand Down Expand Up @@ -2442,6 +2453,10 @@ def test_end2end_ventoux_full_output_no_elevation():
"disparity_margin": 0.25,
"save_intermediate_data": True,
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
},
}
advanced_config = {"save_intermediate_data": True}

Expand Down Expand Up @@ -2840,6 +2855,7 @@ def test_end2end_ventoux_with_color():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"loader": "pandora",
"save_intermediate_data": True,
"use_global_disp_range": False,
Expand Down Expand Up @@ -3099,6 +3115,7 @@ def test_end2end_ventoux_with_classif():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"loader": "pandora",
"save_intermediate_data": True,
"use_global_disp_range": False,
Expand Down Expand Up @@ -3274,6 +3291,7 @@ def test_compute_dsm_with_roi_ventoux():
"resampling": {"method": "bicubic", "strip_height": 80},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"sparse_matching": {
Expand Down Expand Up @@ -3435,6 +3453,7 @@ def test_compute_dsm_with_snap_to_img1():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"triangulation": {
Expand Down Expand Up @@ -3554,6 +3573,7 @@ def test_end2end_quality_stats():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"point_cloud_outliers_removing.1": {
Expand Down Expand Up @@ -3847,6 +3867,7 @@ def test_end2end_ventoux_egm96_geoid():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"triangulation": {"method": "line_of_sight_intersection"},
Expand Down Expand Up @@ -3979,6 +4000,7 @@ def test_end2end_ventoux_egm96_geoid():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"triangulation": {"method": "line_of_sight_intersection"},
Expand Down Expand Up @@ -4069,6 +4091,7 @@ def test_end2end_ventoux_egm96_geoid():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"triangulation": {"method": "line_of_sight_intersection"},
Expand Down Expand Up @@ -4212,6 +4235,7 @@ def test_end2end_paca_with_mask():
},
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"use_global_disp_range": False,
},
"dense_matches_filling.2": {
Expand Down Expand Up @@ -4323,6 +4347,7 @@ def test_end2end_disparity_filling():
dense_dsm_applications = {
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"min_epi_tile_size": 100,
"save_intermediate_data": True,
"use_global_disp_range": False,
Expand Down Expand Up @@ -4455,6 +4480,7 @@ def test_end2end_disparity_filling_with_zeros():
dense_dsm_applications = {
"dense_matching": {
"method": "census_sgm",
"use_cross_validation": True,
"save_intermediate_data": True,
"use_global_disp_range": True,
},
Expand Down

0 comments on commit a1b00d2

Please sign in to comment.