-
Notifications
You must be signed in to change notification settings - Fork 31.2k
Make is_thing_map in Feature Extractor post_process_panoptic_segmentation defaults to all instances #15954
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
Make is_thing_map in Feature Extractor post_process_panoptic_segmentation defaults to all instances #15954
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
Narsil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not particularly fond of the names thing vs stuff but I imagine this is the standards ?
More or less :) |
Narsil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will approve since thing and stuff seem to be standard in that case.
A more descriptive name seems more suitable from a pure code standpoint so I'll let you decide @FrancescoSaverioZuppichini
What I had in mind was more along the lines of:
ids_to_fuse: Set[int], *optional* : If the id is in the set, then only 1 instance of them can be outputted, for instance the class sky could not be part of 2 separate instances. If no map is passed, no fusion occurs.
Other name options that come to mind:
class_ids_to_fusemergemight be better thanfuse.single_instance_classes/idssingleton_ids
No need to use a Dict imo, since the default is not fusing, not belonging to the dict would mean not fusing, and so the dict values become redundant.
And the name really describes how it is used.
|
Thanks @Narsil for the very nice feedback. Following your amazing set of examples, I believe As you said, a I'll update the code. |
| "id": current_segment_id, | ||
| "category_id": pred_class, | ||
| "is_thing": not is_stuff, | ||
| "label_id": pred_class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change will break pipelines actually.
Tagging @sgugger for visibility of this BC.
The pipeline addition is so new that I am OK aligning here for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know, I changed them to reflect the new naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pipeline for Maskformer was not included in the release I believe, so ok to break IMO!
| # check if pred_class should be fused. For example, class "sky" cannot have more then one instance | ||
| should_fuse = False | ||
| if label_ids_to_fuse is not None: | ||
| should_fuse = pred_class in label_ids_to_fuse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forcing label_ids_to_fuse early on to be a set (maybe empty) is IMO better, since you can start relying on the variable type instead of having if ... None everywhere.
if label_ids_to_fuse is None:
logger.warning("`label_ids_to_fuse` unset. No instance will be fused.")
label_ids_to_fuse = set()And then here.:
should_fuse = pred_class in label_ids_to_fuseNo check necessary, you already changed label_ids_to_fuse to be a set.
Again the only reason why you don't use my_function(....label_ids_to_fuse=set()) is because set is mutable.
With immutable types (like tuple) it would be preferable to use a default argument imo.
Note: Technically you can use
frozensetas the default argument but my personal take is that keeping things simple withNoneas default argument is easy enough and understandable toofrozensetis not that widely used.
To be fair,setitself is probably not used that much either, but it does have a generator comprehension at leastmyset = {letter for letter in "hello"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree, thanks for pointing that out! Updated
sgugger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
src/transformers/models/maskformer/feature_extraction_maskformer.py
Outdated
Show resolved
Hide resolved
| "id": current_segment_id, | ||
| "category_id": pred_class, | ||
| "is_thing": not is_stuff, | ||
| "label_id": pred_class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pipeline for Maskformer was not included in the release I believe, so ok to break IMO!
What does this PR do?
Following a discussion with @Narsil , argument
is_thing_mapinFeatureExtractor.post_process_panoptic_segmentationwill default to consider all instancesthing. Thus, it won't perform instances merging.The user should always provide a correct
is_thing_mapif he wants to merge instances, currently, the code will default toCOCOthat may be unwanted.