Repository navigation
Return scores from semantic segmentation post-process - #46163
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
cc @molbap @yonigozlan @NielsRogge, not sure if anyone's working on this already |
|
Oop, didn't realize @guarin was working here! No insult intended 😅 |
|
Following the discussion above, I agree that A related design point from #46139: I think this PR also exposes a broader gap in semantic segmentation APIs. Today, each model/image processor owns its own post-processing path. That makes sense for model-specific restoration, but for users working across models within the same task, it creates extra learning cost: every model family may expose a slightly different final tensor, naming convention, and hard-decision rule. So beyond the immediate naming issue, I wonder if a longer-term direction could be a task-oriented post-processing layer for semantic segmentation. In that design, each processor would still handle model-specific restoration, but would expose a shared pre-final score interface before the hard segmentation map is produced. This kind of unified layer would also give external decoding methods a clearer place to fit. For example, RankSEG-style decoding does not need to change the model or preprocessing; it only replaces the final hard-decision step with a metric-aware decoding method. So it could naturally sit on top of this shared post-processing interface: reuse the official Transformers restoration path, then apply an alternative task-level decoder. Not suggesting that this PR needs to solve the whole abstraction now, but I think the current naming/API discussion is a useful first step toward that direction. |
…arin/transformers into return-seg-postprocess-logits
molbap
left a comment
There was a problem hiding this comment.
Thanks for iterating! I think this can get out of "draft" mode at this point haha
|
@Leev1s that's a valid concern! Definitely too much for this PR but something to keep in mind for the future. We'll have to see how much user interest there is for this feature. Making all possible outputs configurable will increase the number of arguments and code branching quite a bit. |
|
@guarin Thanks for the response.🤗 The reason I'm still pushing a bit on this is that the current implementation makes I think a paired opt-in flag keeps the current PR's default behavior unchanged while making the separation explicit: return_segmentation_scores=True
return_segmentation=Falsewould return restored scores with |
|
Sent a small follow-up PR to make the |
|
@Leev1s the current pattern with Do you have a particular use-case that benefits from excluding the segmentation computation completely that goes beyond the minor speed-up due to skipping the extra |
vasqu
left a comment
There was a problem hiding this comment.
Pretty satisfied with the current state. Just a few last comments from my side
Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com>
stevhliu
left a comment
There was a problem hiding this comment.
thanks for adding docs! just a few minor nits :)
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
|
[For maintainers] Suggested jobs to run (before merge) run-slow: beit, chmv2, conditional_detr, deformable_detr, detr, dpt, eomt, grounding_dino, mask2former, maskformer, mobilenet_v2, mobilevit, oneformer, sam3, sapiens2, segformer |
fc5401d
) * Add return_logits * Add SemanticSegmentationPostProcessOutput * update copyright date * rename to PostProcessorOutput * update ConditionalDetr * align docstrings * update Detr * update Dpt * update Eomt * update Mask2former * update MobileNet * update MobileVit * update Oneformer * update Sam3 * update VideoEomt * update SegGpt * unify variable names * speed up semantic_map computation * remove SemanticSegmentationPostProcessorOutputs from global __init__ * add tests * remove extra tests * fix Eomt tests * inherit from BatchFeature * add PostProcessSemanticSegmentationTestMixin * fix test * remove dataclass from PostProcessorOutput * add post processor docs * add comment * Update src/transformers/image_processing_outputs.py Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com> * Update docs/source/en/add_vision_processing_components.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> * Update docs/source/en/add_vision_processing_components.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> * Update docs/source/en/add_vision_processing_components.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> * Update docs/source/en/add_vision_processing_components.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> * Update docs/source/en/add_vision_processing_components.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> --------- Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com> Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>


What does this PR do?
Adds a new
return_segmentation_scores: bool = Falseargument to allpost_process_semantic_segmentationmethods. IfTrue, the method will return segmentation maps and scores. IfFalse, only the segmentation maps are returned.This changes the return type from all
post_process_semantic_segmentationmethods from:to
SemanticSegmentationPostProcessorOutputis a new addition based onBatchFeatureand is intended to be used as return type frompost_processmethods instead of the untyped dicts that we currently return. The class is fully backwards compatible withdict.Fixes # (issue)
Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.
PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.
This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read
CONTRIBUTING.md.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.