Skip to content

Commit

Permalink
- fixes a small bug with detection_filter so that instance methods (#308
Browse files Browse the repository at this point in the history
)

should work...so hypothetically one could create a detection filter
  like:

```python
class DetectionFilter():

    def init(self, data):
        self.data = data

    def __call__(self, box, mask, logit, phrase, i):
        return phrase == self.data

sam.predict(..., detection_filter=DetectionFilter(data='mystring'))
```
  • Loading branch information
brendancol authored Aug 20, 2024
1 parent 409953a commit 1c54f5d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions samgeo/text_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def predict(
save_args (dict, optional): Save arguments for the prediction. Defaults to {}.
return_results (bool, optional): Whether to return the results. Defaults to False.
detection_filter (callable, optional):
Callable which with box, mask, logit, phrase, and index args returns a boolean.
Callable with box, mask, logit, phrase, and index args returns a boolean.
If provided, the function will be called for each detected object.
Defaults to None.
Expand Down Expand Up @@ -325,8 +325,7 @@ def predict(
if not callable(detection_filter):
raise ValueError("detection_filter must be callable.")

req_nargs = 6 if inspect.ismethod(detection_filter) else 5
if not len(inspect.signature(detection_filter).parameters) == req_nargs:
if not len(inspect.signature(detection_filter).parameters) == 5:
raise ValueError(
"detection_filter required args: "
"box, mask, logit, phrase, and index."
Expand Down

0 comments on commit 1c54f5d

Please sign in to comment.