Skip to content

Commit

Permalink
refactoring detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
rabah-khalek committed Aug 19, 2024
1 parent b69524c commit 98eb356
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from giskard_vision.core.dataloaders.wrappers import BlurredDataLoader

from ...core.detectors.decorator import maybe_detector
from .decorator import maybe_detector
from .perturbation import PerturbationBaseDetector


@maybe_detector(
"blurring",
"blur",
tags=[
"blur",
"vision",
"robustness",
"image_classification",
"landmark_detection",
"object_detection",
],
)
class TransformationBlurringDetector(PerturbationBaseDetector):
class BlurDetector(PerturbationBaseDetector):
"""
Detector that evaluates models performance on blurred images
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from giskard_vision.core.dataloaders.wrappers import ColoredDataLoader

from ...core.detectors.decorator import maybe_detector
from .decorator import maybe_detector
from .perturbation import PerturbationBaseDetector


@maybe_detector(
"coloring",
"color",
tags=[
"vision",
"robustness",
"image_classification",
"landmark_detection",
"object_detection",
"coloring",
"color",
],
)
class TransformationColorDetector(PerturbationBaseDetector):
class ColorDetector(PerturbationBaseDetector):
"""
Detector that evaluates models performance depending on images in grayscale
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Surrogate:
surrogate: Optional[Callable] = None


class MetaDataScanDetector(DetectorVisionBase):
class MetaDataDetector(DetectorVisionBase):
"""
Detector based on Giskard scan that looks for issues based on metadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from giskard_vision.core.dataloaders.wrappers import NoisyDataLoader

from ...core.detectors.decorator import maybe_detector
from .decorator import maybe_detector
from .perturbation import PerturbationBaseDetector


Expand All @@ -15,7 +15,7 @@
"noise",
],
)
class TransformationNoiseDetector(PerturbationBaseDetector):
class NoiseDetector(PerturbationBaseDetector):
"""
Detector that evaluates models performance on noisy images
"""
Expand Down
4 changes: 2 additions & 2 deletions giskard_vision/image_classification/detectors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .metadata_detector import MetaDataScanDetectorClassification
from .metadata_detector import MetaDataDetectorClassification

__all__ = [
"MetaDataScanDetectorClassification",
"MetaDataDetectorClassification",
]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from giskard_vision.core.detectors.metadata_scan_detector import MetaDataScanDetector
from giskard_vision.core.detectors.metadata_detector import MetaDataDetector

from ...core.detectors.decorator import maybe_detector
from .specs import DetectorSpecs


@maybe_detector("metadata_classification", tags=["vision", "image_classification", "metadata"])
class MetaDataScanDetectorClassification(DetectorSpecs, MetaDataScanDetector):
class MetaDataDetectorClassification(DetectorSpecs, MetaDataDetector):
pass
12 changes: 6 additions & 6 deletions giskard_vision/landmark_detection/detectors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .cropping_detector import CroppingDetectorLandmark
from .metadata_detector import MetaDataScanDetectorLandmark
from .transformation_resize_detector import TransformationResizeDetectorLandmark
from .crop_detector import CropDetectorLandmarkDetection
from .metadata_detector import MetaDataDetectorLandmarkDetection
from .resize_detector import TransformationResizeDetectorLandmarkDetection

__all__ = [
"CroppingDetectorLandmark",
"TransformationResizeDetectorLandmark",
"MetaDataScanDetectorLandmark",
"CropDetectorLandmarkDetection",
"TransformationResizeDetectorLandmarkDetection",
"MetaDataDetectorLandmarkDetection",
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from .base import LandmarkDetectionBaseDetector


@maybe_detector("cropping_landmark", tags=["vision", "face", "landmark_detection", "transformed", "cropped"])
class CroppingDetectorLandmark(LandmarkDetectionBaseDetector):
@maybe_detector("crop_landmark_detection", tags=["vision", "face", "landmark_detection", "transformed", "crop"])
class CropDetectorLandmarkDetection(LandmarkDetectionBaseDetector):
"""
Detector that evaluates models performance relative to a facial part
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from giskard_vision.core.detectors.metadata_scan_detector import MetaDataScanDetector
from giskard_vision.core.detectors.metadata_detector import MetaDataDetector
from giskard_vision.landmark_detection.detectors.surrogate_functions import (
SurrogateNME,
SurrogateVolumeConvexHull,
Expand All @@ -8,6 +8,6 @@
from .specs import DetectorSpecs


@maybe_detector("metadata_landmark", tags=["vision", "face", "landmark_detection", "metadata"])
class MetaDataScanDetectorLandmark(DetectorSpecs, MetaDataScanDetector):
@maybe_detector("metadata_landmark_detection", tags=["vision", "face", "landmark_detection", "metadata"])
class MetaDataDetectorLandmarkDetection(DetectorSpecs, MetaDataDetector):
surrogates = [SurrogateVolumeConvexHull, SurrogateNME]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from .base import LandmarkDetectionBaseDetector


@maybe_detector("resize_landmark", tags=["vision", "face", "landmark_detection", "transformed", "resized"])
class TransformationResizeDetectorLandmark(LandmarkDetectionBaseDetector):
@maybe_detector("resize_landmark_detection", tags=["vision", "face", "landmark_detection", "transformed", "resize"])
class TransformationResizeDetectorLandmarkDetection(LandmarkDetectionBaseDetector):
"""
Detector that evaluates models performance on resized images
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from scipy.spatial import ConvexHull

from giskard_vision.core.detectors.metadata_scan_detector import Surrogate
from giskard_vision.core.detectors.metadata_detector import Surrogate
from giskard_vision.landmark_detection.tests.performance import NMEMean
from giskard_vision.landmark_detection.types import PredictionResult

Expand Down
4 changes: 2 additions & 2 deletions giskard_vision/object_detection/detectors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .metadata_detector import MetaDataScanDetectorObjectDetection
from .metadata_detector import MetaDataDetectorObjectDetection

__all__ = [
"MetaDataScanDetectorObjectDetection",
"MetaDataDetectorObjectDetection",
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from giskard_vision.core.detectors.metadata_scan_detector import MetaDataScanDetector
from giskard_vision.core.detectors.metadata_detector import MetaDataDetector
from giskard_vision.object_detection.detectors.surrogate_functions import (
SurrogateArea,
SurrogateAspectRatio,
Expand All @@ -21,7 +21,7 @@


@maybe_detector("metadata_object_detection", tags=["vision", "object_detection", "metadata"])
class MetaDataScanDetectorObjectDetection(DetectorSpecs, MetaDataScanDetector):
class MetaDataDetectorObjectDetection(DetectorSpecs, MetaDataDetector):
surrogates = [
SurrogateCenterMassX,
SurrogateCenterMassY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from giskard_vision.core.detectors.metadata_scan_detector import Surrogate
from giskard_vision.core.detectors.metadata_detector import Surrogate


@staticmethod
Expand Down
32 changes: 13 additions & 19 deletions tests/landmark_detection/detectors/test_detectors.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
from giskard.scanner.issues import Issue, IssueLevel
from pytest import mark

from giskard_vision.core.detectors.transformation_blurring_detector import (
TransformationBlurringDetector,
)
from giskard_vision.core.detectors.transformation_color_detector import (
TransformationColorDetector,
)
from giskard_vision.core.detectors.transformation_noise_detector import (
TransformationNoiseDetector,
)
from giskard_vision.core.detectors.blur_detector import BlurDetector
from giskard_vision.core.detectors.color_detector import ColorDetector
from giskard_vision.core.detectors.noise_detector import NoiseDetector
from giskard_vision.landmark_detection.detectors import (
CroppingDetectorLandmark,
MetaDataScanDetectorLandmark,
TransformationResizeDetectorLandmark,
CropDetectorLandmarkDetection,
MetaDataDetectorLandmarkDetection,
TransformationResizeDetectorLandmarkDetection,
)
from giskard_vision.landmark_detection.detectors.base import ScanResult


@mark.parametrize(
"detector",
[
CroppingDetectorLandmark,
TransformationBlurringDetector,
TransformationColorDetector,
TransformationNoiseDetector,
TransformationResizeDetectorLandmark,
CropDetectorLandmarkDetection,
BlurDetector,
ColorDetector,
NoiseDetector,
TransformationResizeDetectorLandmarkDetection,
],
)
def test_base_detector(opencv_model, dataset_300w, detector):
Expand All @@ -43,10 +37,10 @@ def test_base_detector(opencv_model, dataset_300w, detector):


def test_meta_detector(opencv_model, dataset_ffhq):
results = MetaDataScanDetectorLandmark().get_results(opencv_model, dataset_ffhq)
results = MetaDataDetectorLandmarkDetection().get_results(opencv_model, dataset_ffhq)
assert isinstance(results, list)

issues = MetaDataScanDetectorLandmark().get_issues(
issues = MetaDataDetectorLandmarkDetection().get_issues(
opencv_model, dataset_ffhq, results, (IssueLevel.MINOR, IssueLevel.MEDIUM, IssueLevel.MAJOR)
)
assert isinstance(issues, list)

0 comments on commit 98eb356

Please sign in to comment.