Skip to content

Commit

Permalink
optional ground truth, required input path
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvermeeren-swisstopo committed Jul 24, 2024
1 parent 9bf677e commit d21d8a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/stratigraphy/benchmark/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,22 @@ def evaluate_layer_extraction(predictions: dict, number_of_truth_values: dict) -
return _metrics, document_level_metrics


def create_predictions_objects(predictions: dict, ground_truth_path: Path) -> tuple[dict[FilePredictions], dict]:
def create_predictions_objects(
predictions: dict, ground_truth_path: Path | None
) -> tuple[dict[FilePredictions], dict]:
"""Create predictions objects from the predictions and evaluate them against the ground truth.
Args:
predictions (dict): The predictions from the predictions.json file.
ground_truth_path (Path): The path to the ground truth file.
ground_truth_path (Path | None): The path to the ground truth file.
Returns:
tuple[dict[FilePredictions], dict]: The predictions objects and the number of ground truth values per file.
"""
try: # for inference no ground truth is available
if ground_truth_path and os.path.exists(ground_truth_path): # for inference no ground truth is available
ground_truth = GroundTruth(ground_truth_path)
ground_truth_is_present = True
except FileNotFoundError:
else:
logging.warning("Ground truth file not found.")
ground_truth_is_present = False

Expand Down
11 changes: 6 additions & 5 deletions src/stratigraphy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
@click.option(
"-i",
"--input-directory",
required=True,
type=click.Path(exists=True, path_type=Path),
help="Path to the input directory, or path to a single pdf file.",
)
@click.option(
"-g",
"--ground-truth-path",
type=click.Path(exists=False, path_type=Path),
help="Path to the ground truth file.",
type=click.Path(exists=True, path_type=Path),
help="Path to the ground truth file (optional).",
)
@click.option(
"-o",
Expand Down Expand Up @@ -69,7 +70,7 @@
)
def click_pipeline(
input_directory: Path,
ground_truth_path: Path,
ground_truth_path: Path | None,
out_directory: Path,
predictions_path: Path,
skip_draw_predictions: bool = False,
Expand All @@ -84,7 +85,7 @@ def click_pipeline(
\f
Args:
input_directory (Path): The directory containing the pdf files. Can also be the path to a single pdf file.
ground_truth_path (Path): The path to the ground truth file json file.
ground_truth_path (Path | None): The path to the ground truth file json file.
out_directory (Path): The directory to store the evaluation results.
predictions_path (Path): The path to the predictions file.
skip_draw_predictions (bool, optional): Whether to skip drawing predictions on pdf pages. Defaults to False.
Expand Down Expand Up @@ -119,7 +120,7 @@ def start_pipeline(
Args:
input_directory (Path): The directory containing the pdf files. Can also be the path to a single pdf file.
ground_truth_path (Path): The path to the ground truth file json file.
ground_truth_path (Path | None): The path to the ground truth file json file.
out_directory (Path): The directory to store the evaluation results.
predictions_path (Path): The path to the predictions file.
skip_draw_predictions (bool, optional): Whether to skip drawing predictions on pdf pages. Defaults to False.
Expand Down

1 comment on commit d21d8a5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/stratigraphy
   __init__.py8188%11
   extract.py1881880%3–482
   get_files.py19190%3–47
   line_detection.py26260%3–76
   main.py95950%3–237
src/stratigraphy/util
   boundarydepthcolumnvalidator.py412051%47, 57, 60, 81–84, 109–127, 139–148
   coordinate_extraction.py127794%31, 62, 75–76, 80, 205, 328
   dataclasses.py32391%37–39
   depthcolumn.py1946467%26, 30, 51, 57, 60–61, 85, 88, 95, 102, 110–111, 121, 138–154, 192, 229, 248–256, 267, 272, 279, 310, 315–322, 337–338, 381–423
   depthcolumnentry.py26773%12, 15, 29–30, 33, 45, 52
   description_block_splitter.py70297%24, 139
   draw.py80800%3–244
   duplicate_detection.py51510%3–146
   extract_text.py27293%38–39
   find_depth_columns.py91693%42–43, 71, 83, 176–177
   find_description.py632856%27–35, 50–63, 79–95, 172–175
   geometric_line_utilities.py86298%82, 132
   interval.py1065548%24–27, 31–34, 39, 44, 47, 57–59, 99–145, 166, 171–187
   language_detection.py18180%3–45
   layer_identifier_column.py91910%3–227
   line.py49492%25, 42, 51, 98
   linesquadtree.py46198%76
   plot_utils.py43430%3–120
   predictions.py1301300%3–272
   textblock.py74889%27, 51, 63, 75, 98, 119, 127, 155
   util.py401855%22, 40–47, 61–63, 87–88, 100–105
TOTAL182196947% 

Tests Skipped Failures Errors Time
61 0 💤 0 ❌ 0 🔥 0.928s ⏱️

Please sign in to comment.