Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

add predict_kwargs in ObjectDetectionModel in order to filter the pre… #990

Conversation

Actis92
Copy link
Contributor

@Actis92 Actis92 commented Nov 22, 2021

…diction using custom threshold and manage other parameters

What does this PR do?

In this PR I have added the possibility to specify predict_kwargs for ObjectDetector that can be used to add additional parameters that are used during the prediction step. For example is possible to specify a custom threshold in order to filter the bounding boxes predicted by Icevision. And added setter method in order to allow user to update the values
Fixes #954

…diction using custom treshold and manage other parameters
@codecov
Copy link

codecov bot commented Nov 22, 2021

Codecov Report

Merging #990 (98563c4) into master (f48fe2f) will decrease coverage by 0.05%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #990      +/-   ##
==========================================
- Coverage   88.45%   88.40%   -0.06%     
==========================================
  Files         250      250              
  Lines       13158    13190      +32     
==========================================
+ Hits        11639    11660      +21     
- Misses       1519     1530      +11     
Flag Coverage Δ
unittests 88.40% <80.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
flash/image/instance_segmentation/model.py 93.33% <71.42%> (-6.67%) ⬇️
flash/image/keypoint_detection/model.py 90.90% <71.42%> (-9.10%) ⬇️
flash/image/detection/model.py 95.45% <85.71%> (-4.55%) ⬇️
flash/core/integrations/icevision/adapter.py 93.24% <100.00%> (+0.09%) ⬆️
flash/core/hooks.py 80.00% <0.00%> (-20.00%) ⬇️
flash/text/seq2seq/translation/model.py 68.18% <0.00%> (-6.82%) ⬇️
flash/core/trainer.py 85.93% <0.00%> (-2.07%) ⬇️
flash/core/model.py 87.95% <0.00%> (+0.04%) ⬆️
flash/core/utilities/imports.py 91.30% <0.00%> (+0.06%) ⬆️
flash/core/finetuning.py 92.40% <0.00%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f48fe2f...98563c4. Read the comment docs.

Copy link
Collaborator

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

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

Awesome, looking great! @Actis92 mind also adding this to the instance segmentation and keypoint detection tasks? They are also using the IceVision adapter under the hood 😃

@Actis92
Copy link
Contributor Author

Actis92 commented Nov 22, 2021

@ethanwharris I have added this parameter to the instance segmentation and keypoint detection tasks. Let me know if it's needed something more :)

@ethanwharris ethanwharris added the enhancement New feature or request label Nov 22, 2021
Copy link
Collaborator

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

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

Awesome, I think we could make the setter slightly cleaner but just a minor point 😃 Also, mind updating the CHANGELOG?

Comment on lines 83 to 85
def set_predict_kwargs(self, value):
"""This function is used to update the kwargs used for the prediction step."""
self.adapter.predict_kwargs = value
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be cleaner to do this with properties. Something like:

Suggested change
def set_predict_kwargs(self, value):
"""This function is used to update the kwargs used for the prediction step."""
self.adapter.predict_kwargs = value
@property
def predict_kwargs(self) -> Dict[str, Any]:
"""The kwargs used for the prediction step."""
return self.adapter.predict_kwargs
@predict_kwargs.setter
def predict_kwargs(predict_kwargs: Dict[str, Any]):
self.adapter.predict_kwargs = predict_kwargs

One day we should find a way for this sort of thing to exist on the adapter and automatically be attached here...

Copy link
Contributor Author

@Actis92 Actis92 Nov 23, 2021

Choose a reason for hiding this comment

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

Hi @ethanwharris I will do the changes, both CHANGELOG and the properties. For what concern how to do it automatically, I think that a way is that to automatically update the attribute __dict__ of the class, taking the properties from the adapter or something like that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have done the changes

Copy link
Collaborator

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

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

Nice! LGTM 😃

@ethanwharris ethanwharris merged commit 504c4c2 into Lightning-Universe:master Nov 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to specify the detection_threshold in the prediction method of ObjectDetector
2 participants