Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude classes from inference using pretrained or custom models #1104

Merged
merged 10 commits into from
Mar 6, 2025

Conversation

gguzzy
Copy link
Contributor

@gguzzy gguzzy commented Dec 2, 2024

Hello dear all,
I am writing you to share and open a PR to include in your framework the option to exclude certain classes from inferences/predictions performed, since I found this useful in general.

This allows us to exclude predictions which are not considered by a custom user.

This can be done by using two new optional parameters which are: exclude_classes_names and exclude_classes_id.

Recall to use the same notation for class names and ids accordingly to the loaded model.

I introduced an example which shows the usage of the new parameter, added to folder tests as test_exclude_classes.py'

The methods which include the new parameters are the ones which are responsible for predictions, which are 'prediction, get_sliced_prediction, get_prediction' and their respective usages inside the 'predict.py' class.

gguzzy and others added 2 commits December 2, 2024 18:59
…ls on SAHI - Pull request

1. This feature allows to perform 'predict', 'get_sliced_prediction', and 'get_prediction' inserting a new custom parameter. An example is provided in the code 'test_exclude_classes.py'
Copy link
Contributor Author

@gguzzy gguzzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only one thing missing is adding these new parameters into the methods definitions (the comments explaining the parameters, and not adding it to the method as parameter, which has been already done), it is not such a huge issue to deal with. Waiting for your review and approval.

@gguzzy
Copy link
Contributor Author

gguzzy commented Dec 21, 2024

I updated the code and workflow also using both black and isort. Waiting for your approval.

@gguzzy
Copy link
Contributor Author

gguzzy commented Jan 30, 2025

I removed the test on exclude classes cause it was inserting conflicts on the tests levels. I am waiting for your approval

@gguzzy
Copy link
Contributor Author

gguzzy commented Feb 10, 2025

Hi @fcakyon,
any news on when this new feature will be available?

If there is any other feature or things I can do to enhance the project, please let me know or contact me privately, if necessary.

Thanks.

@fcakyon
Copy link
Collaborator

fcakyon commented Feb 19, 2025

Thanks for the work @gguzzy !

We can work to merge your PR after this project refactor PR 👍🏻

@fcakyon fcakyon requested a review from Copilot March 5, 2025 01:17
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces new optional parameters to exclude specific classes from inference results, which can be used with pretrained and custom models. Key changes include the addition of a filter_predictions helper function and modifications to prediction functions (get_prediction, get_sliced_prediction, predict, and predict_fiftyone) to support the exclusion of classes by name or ID.

Reviewed Changes

File Description
sahi/predict.py Added filter_predictions function and integrated optional exclusion parameters into methods

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (2)

sahi/predict.py:73

  • [nitpick] The parameter name 'exclude_classes_by_name' differs from the PR description ('exclude_classes_names'). Aligning the naming will improve clarity and consistency.
exclude_classes_by_name: Optional[List[str]] = None,

sahi/predict.py:74

  • [nitpick] The parameter name 'exclude_classes_by_id' differs from the PR description ('exclude_classes_id'). Consider renaming it to maintain consistency with the documentation.
exclude_classes_by_id: Optional[List[int]] = None,

fcakyon and others added 3 commits March 5, 2025 04:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@fcakyon
Copy link
Collaborator

fcakyon commented Mar 5, 2025

@gguzzy all tests pass!

Can you please add some simple examples of usage for your newly added parameters in this md file? https://github.com/obss/sahi/blob/main/docs/predict.md

@gguzzy
Copy link
Contributor Author

gguzzy commented Mar 5, 2025

@fcakyon, I created a new pull request including a small example as you suggested.

The referenced pull is on #1125

@fcakyon fcakyon self-requested a review March 6, 2025 01:36
@fcakyon fcakyon added this pull request to the merge queue Mar 6, 2025
Merged via the queue into obss:main with commit fa705eb Mar 6, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants