Skip to content

Commit 2ffa970

Browse files
[DEV] filter_labels
1 parent 60dc2b1 commit 2ffa970

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/globox/annotationset.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,23 @@ def _labels(self) -> "set[str]":
168168
return {b.label for b in self.all_boxes}
169169

170170
def filter(self, predicate: Callable[[Annotation], bool]) -> "AnnotationSet":
171+
"""
172+
Filter the dataset by a predicate function that takes an `Annotation` and returns True if the annotation should be kept.
173+
"""
171174
return AnnotationSet(annotations=[a for a in self if predicate(a)])
172175

173176
def map(self, func: Callable[[Annotation], Annotation]) -> "AnnotationSet":
177+
"""
178+
Transform the annotations of the annotation set by applying a function to each annotation.
179+
"""
174180
return AnnotationSet(annotations=[func(a) for a in self])
175181

176182
def filter_labels(
177183
self, labels: Iterable[str], keep_empty: bool = False
178184
) -> "AnnotationSet":
185+
"""
186+
Filter the annotations by keeping only the bounding boxes with labels in the provided iterable.
187+
"""
179188
labels_to_keep = set(labels)
180189

181190
def filter_labels(annotation: "Annotation") -> "Annotation":

0 commit comments

Comments
 (0)