generated from ashleve/lightning-hydra-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from IGNF/workflow-thresolds-optim
Workflow for building validation thresholds optimization
- Loading branch information
Showing
10 changed files
with
204 additions
and
4 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
.github/workflows/building_validation_thresholds_optimization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Workflow name | ||
name: "Building validation thresholds optimization" | ||
|
||
on: | ||
# Run workflow on user request | ||
workflow_dispatch: | ||
inputs: | ||
sampling_name: | ||
description: | | ||
Sampling name : | ||
Nom du dataset sur lequel le modèle a été entraîné. | ||
Utilisé pour générer un chemin standard pour les entrées et sorties dans le | ||
dossier IA du store (projet-LHD/IA/LIDAR-PROD-OPTIMIZATION/$SAMPLING_NAME/$MODEL_ID) | ||
Eg. YYYYMMDD_MonBeauDataset | ||
required: true | ||
model_id: | ||
description: | | ||
Identifiant du modèle : | ||
Utilisé pour générer un chemin standard pour les entrées et sorties dans le | ||
dossier IA du store (projet-LHD/IA/LIDAR-PROD-OPTIMIZATION/$SAMPLING_NAME/$MODEL_ID) | ||
Exemple : YYYMMDD_MonBeauSampling_epochXXX_Myria3Dx.y.z | ||
required: true | ||
|
||
jobs: | ||
optimize-building-validation-thresholds: | ||
runs-on: self-hosted | ||
env: | ||
WORKDIR: /var/data/LIDAR-PROD-OPTIMIZATION/ | ||
IO_DIR: /var/data/LIDAR-PROD-OPTIMIZATION/${{ github.event.inputs.sampling_name }}/${{ github.event.inputs.model_id }}/ | ||
DATA: /var/data/LIDAR-PROD-OPTIMIZATION/20221018_lidar-prod-optimization-on-151-proto/Comparison/ | ||
THRESHOLDS_FILE: valset-opti-results/optimized_thresholds.yaml | ||
OUTPUT_CONFIG_FILE: LIDAR-PROD-${{ github.event.inputs.model_id }}.yaml | ||
nexus_server: docker-registry.ign.fr | ||
|
||
steps: | ||
- name: Log configuration | ||
run: | | ||
echo "Optimize building validation threshold for a given trained model" | ||
echo "Model ID ${{ github.event.inputs.model_id }}" | ||
echo "input/output dir: ${{env.IO_DIR}}" | ||
echo "data: ${{env.DATA}}" | ||
echo "validation input_las_dir: ${{env.IO_DIR}}/preds-valset/" | ||
echo "test input_las_dir: ${{env.IO_DIR}}/preds-testset/" | ||
echo "output thresholds file: ${{env.IO_DIR}}/${{env.THRESHOLDS_FILE}}" | ||
echo "output config file: ${{env.IO_DIR}}/${{env.OUTPUT_CONFIG_FILE}}" | ||
echo "evaluation metrics (on test dataset): ${{env.IO_DIR}}/preds-testset/evaluation.yaml" | ||
- name: Checkout branch | ||
uses: actions/checkout@v4 | ||
|
||
# get version number, to retrieve the docker image corresponding to the current version | ||
- name: Get version number | ||
run: | | ||
echo "VERSION=$(docker run lidar_prod python -m lidar_prod.version)" >> $GITHUB_ENV | ||
- name: pull docker image tagged with current version | ||
run: | | ||
docker pull ${{ env.nexus_server }}/lidar_hd/lidar_prod:${{ env.VERSION }} | ||
- name: Optimization and evaluation on validation dataset | ||
run: > | ||
docker run --network host | ||
-v ${{env.IO_DIR}}:/io_dir | ||
${{ env.nexus_server }}/lidar_hd/lidar_prod:${{ env.VERSION }} | ||
python lidar_prod/run.py | ||
++task=optimize_building | ||
building_validation.optimization.todo='prepare+optimize+evaluate+update' | ||
building_validation.optimization.paths.input_las_dir=/io_dir/preds-valset/ | ||
building_validation.optimization.paths.results_output_dir=/io_dir/valset-opti-results/ | ||
building_validation.optimization.paths.output_optimized_config=/io_dir/${{env.OUTPUT_CONFIG_FILE}} | ||
hydra.run.dir=/io_dir/valset-opti-results/ | ||
- name: Evaluation on test dataset | ||
run: > | ||
docker run --network=host | ||
-v ${{env.IO_DIR}}:/io_dir | ||
${{ env.nexus_server }}/lidar_hd/lidar_prod:${{ env.VERSION }} | ||
python lidar_prod/run.py | ||
++task=optimize_building | ||
building_validation.optimization.todo='prepare+evaluate+update' | ||
building_validation.optimization.paths.input_las_dir=/io_dir/preds-testset/ | ||
building_validation.optimization.paths.results_output_dir=/io_dir/testset-opti-results/ | ||
building_validation.optimization.paths.building_validation_thresholds=/io_dir/${{env.THRESHOLDS_FILE}} | ||
building_validation.optimization.paths.evaluation_results_yaml=/io_dir/preds-testset/evaluation.yaml | ||
hydra.run.dir=/io_dir/testset-opti-results/ | ||
- name: Log evaluation results on test dataset | ||
run: | | ||
echo "Evaluation results on the test dataset" | ||
echo "The most important metric to inspect is: p_auto (automation proportion)" | ||
echo "" | ||
cat ${{env.IO_DIR}}/preds-testset/evaluation.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "V1.10.2" | ||
__version__ = "V1.10.3" | ||
|
||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
import os.path as osp | ||
import shutil | ||
from pathlib import Path | ||
|
||
from omegaconf import OmegaConf | ||
|
||
from lidar_prod.optimization import optimize_building | ||
|
||
TMP_DIR = Path("tmp/lidar_prod/optimization") | ||
LAS_SUBSET_FILE = "tests/files/870000_6618000.subset.postIA.corrected.las" | ||
|
||
|
||
def setup_module(module): | ||
try: | ||
shutil.rmtree(TMP_DIR) | ||
except FileNotFoundError: | ||
pass | ||
TMP_DIR.mkdir(parents=True, exist_ok=True) | ||
|
||
|
||
def test_optimize_building_on_subset(hydra_cfg): | ||
out_dir = str(TMP_DIR / "subset") | ||
# Optimization output (thresholds and prepared/updated LASfiles) saved to out_dir | ||
hydra_cfg.building_validation.optimization.paths.results_output_dir = out_dir | ||
|
||
# We isolate the input file in a subdir, and prepare it for optimization | ||
input_las_dir = osp.join(out_dir, "inputs/") | ||
hydra_cfg.building_validation.optimization.paths.input_las_dir = input_las_dir | ||
hydra_cfg.building_validation.application.thresholds = "NO THRESHOLDS" | ||
os.makedirs(input_las_dir, exist_ok=False) | ||
src_las_copy_path = osp.join(input_las_dir, "copy.las") | ||
shutil.copy(LAS_SUBSET_FILE, src_las_copy_path) | ||
|
||
optimize_building(hydra_cfg) | ||
|
||
# Check that the expected outputs are saved successfully | ||
th_yaml = hydra_cfg.building_validation.optimization.paths.building_validation_thresholds | ||
assert os.path.isfile(th_yaml) | ||
cfg_yaml = hydra_cfg.building_validation.optimization.paths.output_optimized_config | ||
assert os.path.isfile(cfg_yaml) | ||
|
||
assert os.path.isfile(osp.join(out_dir, "prepared", osp.basename(src_las_copy_path))) | ||
updated_las_path = osp.join(out_dir, "updated", osp.basename(src_las_copy_path)) | ||
assert os.path.isfile(updated_las_path) | ||
|
||
# Check that thte thresholds are saved correctly in output config file | ||
out_cfg = OmegaConf.load(cfg_yaml) | ||
assert out_cfg.building_validation.application.thresholds != "NO THRESHOLDS" |