Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
05a4cc2
working on perturbation detectors
rabah-khalek Aug 8, 2024
cf2a8c4
Refactor HF ppl model to convert numpy array to PIL image
Inokinoki Aug 5, 2024
7ba35b6
Allow to set global mode for an HF ppl model for PIL conversion
Inokinoki Aug 5, 2024
6c3ffc9
mode switch in hf models
rabah-khalek Aug 8, 2024
7e14795
supporting gray scale
rabah-khalek Aug 8, 2024
f3d8e32
Merge branch 'main' into perturbation-detectors
rabah-khalek Aug 8, 2024
c30dade
Merge branch 'main' into perturbation-detectors
rabah-khalek Aug 10, 2024
98baa6d
added missing predict_rgb_image
rabah-khalek Aug 12, 2024
a9fa22f
ensuring backward compatibility with predict_image
rabah-khalek Aug 12, 2024
e9198ce
updating detectors
rabah-khalek Aug 12, 2024
4dd46b4
Adding noise perturbation detector with Gaussian noise (#52)
bmalezieux Aug 12, 2024
e547d4d
updating detectors
rabah-khalek Aug 12, 2024
a44399d
refactoring detectors
rabah-khalek Aug 13, 2024
fe26272
small updates
rabah-khalek Aug 13, 2024
c359c9c
refactored spec setting
rabah-khalek Aug 13, 2024
6dca401
fixed import in object_detection dataloader
rabah-khalek Aug 13, 2024
99d98dd
renaming pert detectors
rabah-khalek Aug 13, 2024
6601ecb
Merge branch 'main' into perturbation-detectors
rabah-khalek Aug 13, 2024
14de1fa
Merge branch 'perturbation-detectors' into refactoring-detectors
rabah-khalek Aug 13, 2024
182731c
fixed import
rabah-khalek Aug 13, 2024
6ba1994
fixing get_scan_results args
rabah-khalek Aug 13, 2024
ffbb425
Merge pull request #53 from Giskard-AI/refactoring-detectors
rabah-khalek Aug 13, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
supporting gray scale
  • Loading branch information
rabah-khalek committed Aug 8, 2024
commit 7e1479599469536d86d9d68e70d905b1a3d2c1e8
26 changes: 24 additions & 2 deletions giskard_vision/core/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,37 @@ class ModelBase(ABC):
prediction_result_cls = TypesBase.prediction_result

@abstractmethod
def predict_image(self, image: np.ndarray) -> Any:
"""abstract method that takes one image as input and outputs the prediction
def predict_rgb_image(self, image: np.ndarray) -> Any:
"""abstract method that takes one RGB image as input and outputs the prediction

Args:
image (np.ndarray): input image
"""

...

def predict_gray_image(self, image: np.ndarray) -> Any:
"""abstract method that takes one gray image as input and outputs the prediction

Args:
image (np.ndarray): input image
"""

raise NotImplementedError("predict_gray_image method is not implemented")

def predict_image(self, image: np.ndarray) -> Any:
"""abstract method that takes one image as input and outputs the prediction

Args:
image (np.ndarray): input image
"""
if image.shape[-1] == 3:
return self.predict_rgb_image(image)
elif image.shape[-1] == 1 or len(image.shape) == 2:
return self.predict_gray_image(image)
else:
raise ValueError("predict_image: image shape not supported.")

def predict_batch(self, idx: int, images: List[np.ndarray]) -> np.ndarray:
"""method that should be implemented if the passed dataloader has batch_size != 1

Expand Down
14 changes: 5 additions & 9 deletions giskard_vision/image_classification/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ def predict_probas(self, image: np.ndarray, mode=None) -> np.ndarray:

return np.array([_prediction[label] for label in self.classification_labels])

def predict_image(self, image, mode=None) -> Types.label:
"""method that takes one image as input and outputs one class label
def predict_rgb_image(self, image: np.ndarray) -> Types.label:
probas = self.predict_probas(image, mode=None)
return self.classification_labels[np.argmax(probas)]

Args:
image (np.ndarray): input image
mode (str): mode of the image
"""
if len(image.shape) == 2:
mode = "L" # Grayscale - Needed to run the color robustness detector
probas = self.predict_probas(image, mode=mode)
def predict_gray_image(self, image: np.ndarray) -> Types.label:
probas = self.predict_probas(image, mode="L")
return self.classification_labels[np.argmax(probas)]
4 changes: 2 additions & 2 deletions giskard_vision/landmark_detection/models/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, model):
super().__init__(n_landmarks=68, n_dimensions=2, name="FaceAlignment")
self.model = model

def predict_image(self, image):
def predict_rgb_image(self, image):
"""
Predict facial landmarks for a given image using the wrapped face alignment model.

Expand Down Expand Up @@ -100,7 +100,7 @@ def __init__(self):
self.landmark_detector = cv2.face.createFacemarkLBF()
self.landmark_detector.loadModel(LBFmodel)

def predict_image(self, image):
def predict_rgb_image(self, image):
"""
Predict facial landmarks for a given image using the wrapped OpenCV face landmarks model.

Expand Down
2 changes: 1 addition & 1 deletion giskard_vision/object_detection/models/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def shape_rescale(self, image, boxes):
def positive_constraint(self, boxes):
return np.clip(boxes, 0, None)

def predict_image(self, image: np.ndarray):
def predict_rgb_image(self, image: np.ndarray):
try:
from keras.applications.mobilenet import preprocess_input
except ImportError:
Expand Down