Skip to content

Commit

Permalink
renaming get_labels -> get_label
Browse files Browse the repository at this point in the history
  • Loading branch information
rabah-khalek committed Aug 19, 2024
1 parent f01cef8 commit 0cbbda0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
14 changes: 7 additions & 7 deletions giskard_vision/core/dataloaders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def meta_none(self) -> Optional[TypesBase.meta]:
"""
return None

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets labels (for a single image) for a specific index.
Expand Down Expand Up @@ -180,7 +180,7 @@ def get_meta(self, idx: int) -> Optional[TypesBase.meta]:
},
)

def get_labels_with_default(self, idx: int) -> np.ndarray:
def get_label_with_default(self, idx: int) -> np.ndarray:
"""
Gets labels for a specific index with a default value if None.
Expand All @@ -190,7 +190,7 @@ def get_labels_with_default(self, idx: int) -> np.ndarray:
Returns:
np.ndarray: Labels for the given index.
"""
labels = self.get_labels(idx)
labels = self.get_label(idx)
return labels if labels is not None else self.labels_none()

def get_meta_with_default(self, idx: int) -> MetaData:
Expand Down Expand Up @@ -219,7 +219,7 @@ def get_single_element(self, idx) -> TypesBase.single_data:
metadata = self.get_meta_with_default(idx)
return (
self.get_image(idx),
self.get_labels_with_default(idx),
self.get_label_with_default(idx),
metadata if metadata is not None else MetaData({}),
)

Expand Down Expand Up @@ -256,7 +256,7 @@ def all_labels(self) -> np.ndarray:
Returns:
np.ndarray: Array containing labels.
"""
return np.array([self.get_labels_with_default(idx) for idx in self.idx_sampler])
return np.array([self.get_label_with_default(idx) for idx in self.idx_sampler])

@property
def all_meta(self) -> List:
Expand Down Expand Up @@ -347,7 +347,7 @@ def get_image(self, idx: int) -> np.ndarray:
"""
return self._wrapped_dataloader.get_image(idx)

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets labels from the wrapped data loader.
Expand All @@ -357,7 +357,7 @@ def get_labels(self, idx: int) -> Optional[np.ndarray]:
Returns:
Optional[np.ndarray]: Labels from the wrapped data loader.
"""
return self._wrapped_dataloader.get_labels(idx)
return self._wrapped_dataloader.get_label(idx)

def get_meta(self, idx: int) -> Optional[TypesBase.meta]:
"""
Expand Down
8 changes: 4 additions & 4 deletions giskard_vision/core/dataloaders/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
lru_cache(maxsize=cache_size)(func) if should_cache else func
for should_cache, func in [
(cache_img, self._wrapped_dataloader.get_image),
(cache_labels, self._wrapped_dataloader.get_labels),
(cache_labels, self._wrapped_dataloader.get_label),
(cache_meta, self._wrapped_dataloader.get_meta),
]
]
Expand All @@ -63,7 +63,7 @@ def get_image(self, idx: int) -> np.ndarray:
"""
return self._cached_functions[0](idx)

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets labels from the cache or the wrapped data loader.
Expand Down Expand Up @@ -154,7 +154,7 @@ def get_image(self, idx: int) -> np.ndarray:
def resize_labels(self, labels: Any, scales: Union[Tuple[float, float], float]) -> Any:
raise NotImplementedError("Method not implemented")

def get_labels(self, idx: int) -> np.ndarray:
def get_label(self, idx: int) -> np.ndarray:
"""
Gets resized labels data based on the specified scales.
Expand All @@ -164,7 +164,7 @@ def get_labels(self, idx: int) -> np.ndarray:
Returns:
np.ndarray: Resized labels.
"""
labels = super().get_labels(idx)
labels = super().get_label(idx)
return self.resize_labels(labels, self._scales)


Expand Down
2 changes: 1 addition & 1 deletion giskard_vision/core/detectors/metadata_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def get_df_for_scan(self, model: Any, dataset: Any, list_metadata: Sequence[str]

image = dataset.get_image(i)
prediction = np.array([model.predict_image(image)]) # batch of 1 prediction
ground_truth = np.array([dataset.get_labels(i)]) # batch of 1 ground truth
ground_truth = np.array([dataset.get_label(i)]) # batch of 1 ground truth
metadata = dataset.get_meta(i)
metric_value = self.metric.get(model.prediction_result_cls(prediction), ground_truth) # expect batches

Expand Down
6 changes: 3 additions & 3 deletions giskard_vision/image_classification/dataloaders/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_image(self, idx: int) -> np.ndarray:
"""
return np.array(self.get_row(idx)["image"])

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Retrieves shape label of the image at the specified index.
Expand Down Expand Up @@ -149,7 +149,7 @@ def get_image(self, idx: int) -> np.ndarray:

return np.array(raw_img)

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Retrieves label of the image at the specified index.
Expand Down Expand Up @@ -252,7 +252,7 @@ def get_image(self, idx: int) -> np.ndarray:

return np.array(raw_img)

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Retrieves label of the image at the specified index.
Expand Down
2 changes: 1 addition & 1 deletion giskard_vision/landmark_detection/dataloaders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_image(self, idx: int) -> np.ndarray:
"""
return self._load_and_validate_image(self.image_paths[idx])

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets marks for a specific index after validation.
Expand Down
4 changes: 2 additions & 2 deletions giskard_vision/landmark_detection/dataloaders/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(
self.images_dir_path = self._get_absolute_local_path(dir_path)
self.image_paths = self._get_all_paths_based_on_suffix(self.images_dir_path, self.image_suffix)

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets landmark coordinates for a specific index.
Expand Down Expand Up @@ -354,7 +354,7 @@ def get_image(self, idx: int) -> np.ndarray:
"""
return self.get_row(idx)[self.image_key]

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Retrieves normalized 2D landmarks corresponding to the image at the specified index.
Expand Down
2 changes: 1 addition & 1 deletion giskard_vision/landmark_detection/dataloaders/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_image(self, idx: int) -> np.ndarray:
image = super().get_image(idx)
h, w, _ = image.shape
margins = np.array([w, h]) * self._margins
marks = crop_mark(self.get_labels_with_default(idx), self._part)
marks = crop_mark(self.get_label_with_default(idx), self._part)
return crop_image_from_mark(image, marks, margins)


Expand Down
14 changes: 7 additions & 7 deletions giskard_vision/object_detection/dataloaders/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_boxes_shape_rescale(self, idx: int) -> ndarray:

return np.array([xmin, ymin, xmax, ymax])

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets landmark coordinates for a specific index.
Expand Down Expand Up @@ -207,15 +207,15 @@ def get_image(self, idx: int) -> np.ndarray:
class DataLoader300WFaceDetection(DataLoader300W):
"""Data loader for the 300W dataset for face detection. Ref: https://ibug.doc.ic.ac.uk/resources/300-W/"""

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets marks for a specific index after validation.
Args:
idx (int): Index of the data.
Returns:
Optional[np.ndarray]: Marks for the given index.
"""
landmarks = super().get_labels(idx)
landmarks = super().get_label(idx)

if landmarks is None:
return None
Expand All @@ -232,15 +232,15 @@ def get_labels(self, idx: int) -> Optional[np.ndarray]:
class DataLoaderFFHQFaceDetectionLandmark(DataLoaderFFHQ):
"""Data loader for the FFHQ (Flickr-Faces-HQ) dataset for face detection, using the boundary boxes around landmarks."""

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets marks for a specific index after validation.
Args:
idx (int): Index of the data.
Returns:
Optional[np.ndarray]: Marks for the given index.
"""
landmarks = super().get_labels(idx)
landmarks = super().get_label(idx)

if landmarks is None:
return None
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(
for k, v in json.load(fp).items()
}

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets marks for a specific index after validation.
Args:
Expand Down Expand Up @@ -398,7 +398,7 @@ def get_boxes_shape_rescale(self, idx: int) -> ndarray:

return np.array([xmin, ymin, xmax, ymax])

def get_labels(self, idx: int) -> Optional[np.ndarray]:
def get_label(self, idx: int) -> Optional[np.ndarray]:
"""
Gets landmark coordinates for a specific index.
Expand Down
4 changes: 2 additions & 2 deletions tests/core/dataloaders/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def idx_sampler(self):
def get_image(self, idx: int) -> np.ndarray:
return self.dataset[idx]

def get_labels(self, idx: int) -> np.ndarray:
def get_label(self, idx: int) -> np.ndarray:
return self.labels[idx]


Expand Down Expand Up @@ -50,7 +50,7 @@ def labels_none(cls):
def meta_none(cls):
return {"key1": -1, "key2": -1}

def get_labels(self, idx: int) -> np.ndarray | None:
def get_label(self, idx: int) -> np.ndarray | None:
return self.labels[idx] if idx % 2 == 0 else None

def get_meta(self, idx: int) -> dict | None:
Expand Down

0 comments on commit 0cbbda0

Please sign in to comment.