diff --git a/giskard_vision/core/detectors/base.py b/giskard_vision/core/detectors/base.py index 09743097..f8a3369c 100644 --- a/giskard_vision/core/detectors/base.py +++ b/giskard_vision/core/detectors/base.py @@ -36,17 +36,21 @@ class ScanResult: relative_delta: float issue_group: Optional[IssueGroup] = None - def get_meta_required(self, add_slice_size=True) -> dict: - # Get the meta required by the original scan API - deviation = f"{self.relative_delta * 100:+.2f}% than global" - extra_meta = dict(slice_size=self.slice_size) if add_slice_size else dict() - return { - "metric": self.metric_name, - "metric_value": self.metric_value, - "metric_reference_value": self.metric_reference_value, - "deviation": deviation, - **extra_meta, - } + +def get_meta_required(self, include_slice_size=True) -> dict: + deviation = f"{self.relative_delta * 100:+.2f}% than global" + + meta_info = { + "metric": self.metric_name, + "metric_value": self.metric_value, + "metric_reference_value": self.metric_reference_value, + "deviation": deviation, + } + + if include_slice_size: + meta_info["slice_size"] = self.slice_size + + return meta_info class DetectorVisionBase(DetectorSpecsBase): @@ -65,8 +69,6 @@ class DetectorVisionBase(DetectorSpecsBase): evaluation results for the scan. """ - slicing: bool = True - def run( self, model: Any, @@ -118,20 +120,20 @@ def get_issues( for result in results: if result.issue_level in issue_levels: - issue_attribute = ( - dict(slicing_fn=result.name, meta=result.get_meta_required()) - if self.slicing - else dict(transformation_fn=result.name, meta=result.get_meta_required(False)) - ) + extra_args = { + "slicing_fn" if self.slicing else "transformation_fn": result.name, + "meta": result.get_meta_required(self.slicing), + } + issues.append( Issue( model, dataset, level=result.issue_level, - group=result.issue_group if result.issue_group else self.issue_group, + group=result.issue_group or self.issue_group, scan_examples=ImagesScanExamples(result.filename_examples, embed=embed), display_footer_info=False, - **issue_attribute, + **extra_args, ) ) diff --git a/giskard_vision/core/detectors/specs.py b/giskard_vision/core/detectors/specs.py index 3bf01c69..d0126112 100644 --- a/giskard_vision/core/detectors/specs.py +++ b/giskard_vision/core/detectors/specs.py @@ -11,3 +11,4 @@ class DetectorSpecsBase: deviation_threshold: float = 0.10 issue_level_threshold: float = 0.05 num_images: int = 0 + slicing: bool = True