[ImageMaskAnnotator]: Adds an annotator to overlay an image over specified classes of detections #1007
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
ImageMaskAnnotator is a new annotator that overlays a user-specified image on detections included in a user-specified list of classes which defaults to class 0 (person for MS-COCO). Specified images can be PNGs, but with clear backgrounds, they are not guaranteed to cover the entire detection. Another barrier is using images with pure-black pixels which often gets turned clear after the overlay.
Motivation for this change was to allow users to redact certain objects or add anonymity to their products in a more customizable way than simply blurring specific detections.
One issue (that is non-breaking) that I would appreciate feedback on is that an IndexError occurs if any point of an object's
xyxy
attribute is outside of the frame, which I mitigated with a try/except loop, but the object is no longer covered in that exception. (Maybe I could add variables to have access to previous positions, but I'd like feedback on how to cover the entire rest of the detection that is inside of the frame).This change does not require any additional dependencies.
Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
There are no unit tests since the change is an additional annotator, but I've tested on my local machine and on colab and it works as intended. Attached is a colab notebook with an example of the change (inspired by @dfreilich 's notebook example):
https://colab.research.google.com/drive/1FkIwwDaSPVvSk2eKRbTeqHT89oZIbCFk?usp=sharing
Any specific deployment considerations
None that I can think of.
Docs
annotators.md was updated to include the new
ImageMaskAnnotator