Skip to content

Add Fast Segformer Processor#37024

Merged
yonigozlan merged 17 commits intohuggingface:mainfrom
capnmav77:main
Jul 28, 2025
Merged

Add Fast Segformer Processor#37024
yonigozlan merged 17 commits intohuggingface:mainfrom
capnmav77:main

Conversation

@capnmav77
Copy link
Copy Markdown
Contributor

@capnmav77 capnmav77 commented Mar 27, 2025

What does this PR do?

Linked: #36978

Adding fast processor for Segformer.

CC: @yonigozlan

@github-actions github-actions Bot marked this pull request as draft March 27, 2025 01:29
@github-actions
Copy link
Copy Markdown
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@capnmav77 capnmav77 marked this pull request as ready for review March 27, 2025 02:18
@github-actions github-actions Bot requested review from ydshieh and yonigozlan March 27, 2025 02:18
- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class
Copy link
Copy Markdown
Member

@yonigozlan yonigozlan left a comment

Choose a reason for hiding this comment

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

Hi @capnmav77 , Thanks for working on this! Looks like the segmentation_maps processing logic from the slow image processor is missing here. You can take a look at how it's being handled for BeitImageProcessorFast as it is very similar to Segformer image processor! Here is the PR BeitImageProcessorFast #37005

…essing module with references from beitimageprocessing fast
@capnmav77
Copy link
Copy Markdown
Contributor Author

capnmav77 commented Mar 28, 2025

Hi @capnmav77 , Thanks for working on this! Looks like the segmentation_maps processing logic from the slow image processor is missing here. You can take a look at how it's being handled for BeitImageProcessorFast as it is very similar to Segformer image processor! Here is the PR BeitImageProcessorFast #37005

hey @yonigozlan i've added the segmentation_maps processing logic from the slow image processor also i've taken references from the beitimageprocessorFast it really helped a lot , do let me know what to do next

@capnmav77 capnmav77 requested a review from yonigozlan March 28, 2025 04:26
Copy link
Copy Markdown
Member

@yonigozlan yonigozlan left a comment

Choose a reason for hiding this comment

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

Hey @capnmav77 thanks a lot for iterating, looks much better! Still a few things to change, and now the important part is to check that all tests pass with

RUN_SLOW=1 python -m pytest tests/models/segformer/test_image_processing_segformer.py

You should also override test_slow_fast_equivalence to also test segmentation maps processing. You can check how it was done in the Beit PR.

Also all the formatting/repo consistency tests should pass. You can use the utilities make fixup, make fix-copies, make style, make quality to help.

Comment thread src/transformers/models/segformer/image_processing_segformer_fast.py Outdated
Comment thread src/transformers/models/segformer/image_processing_segformer_fast.py Outdated
Comment thread src/transformers/models/segformer/image_processing_segformer_fast.py Outdated
Comment thread src/transformers/models/segformer/image_processing_segformer_fast.py Outdated
Comment thread tests/models/segformer/test_image_processing_segformer.py
@capnmav77
Copy link
Copy Markdown
Contributor Author

Hey @yonigozlan , i have modified the code accordingly but there's a issue i'm not able to figure out , one local test fails :

FAILED tests/models/segformer/test_image_processing_segformer.py::SegformerImageProcessingTest::test_slow_fast_equivalence - AssertionError: False is not true

do you have a fix for this i'm not able to understand why this is happening , the dims of the fast processor are 1 , C , H , W , which shouldn't be the case compared to the slow processor which has 1, H , W , i presume the labels are messed up somewhere . Please do lemme know the fix for that and do suggest code changes .

here's the log output of the labels :

tensor([[[ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  3,  3,  2,  2,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  3,  2,  2,  2,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  3,  3,  3,  3,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  3,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18, 18,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18,  2,  2,  2,  2,  2],
         [ 5,  5,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18,  2,  2,  2,  2,  2],
         [ 5,  5,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18,  2,  2,  2,  2,  2],
         [ 5,  5,  5,  5,  5,  5,  5,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18, 18,  2,  2,  2,  2],
         [ 5,  5,  5,  5,  5,  5,  5,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2, 18, 18, 18,  2,  2,  2,  2],
         [ 5,  5,  5,  5,  5,  5,  5,  1,  1,  0,  0,  0,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2, 18, 18, 18,  2,  2,  2,  2],
         [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,
           2,  2,  2,  2,  2,  2, 18, 18, 18,  2,  2,  2,  2],
         [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,
          10, 10,  2,  2,  2, 18, 18, 18, 18, 18, 18, 18,  2],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 18, 18, 18, 18, 18, 18],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10,  7,  7,  7,  7,  7]]])
tensor([[[[ 86,  87,  86,  ...,  82,  81,  80],
          [ 89,  90,  90,  ...,  83,  82,  80],
          [ 90,  92,  93,  ...,  85,  84,  83],
          ...,
          [ 99, 100, 101,  ..., 105, 101,  99],
          [102, 107, 107,  ..., 110, 108, 104],
          [ 97,  97, 103,  ..., 121, 119, 117]],

         [[138, 138, 138,  ..., 132, 131, 131],
          [140, 141, 141,  ..., 133, 132, 131],
          [142, 143, 143,  ..., 135, 134, 132],
          ...,
          [109, 108, 108,  ..., 108, 103, 102],
          [107, 108, 105,  ..., 111, 108, 106],
          [102,  99, 102,  ..., 114, 114, 114]],

         [[191, 193, 194,  ..., 191, 189, 188],
          [194, 196, 197,  ..., 194, 191, 189],
          [196, 199, 200,  ..., 196, 193, 191],
          ...,
          [ 62,  63,  63,  ...,  66,  64,  63],
          [ 62,  66,  66,  ...,  71,  70,  71],
          [ 58,  58,  61,  ..., 100, 102, 102]]]])
          ```

@capnmav77 capnmav77 requested a review from yonigozlan April 2, 2025 04:39
Copy link
Copy Markdown
Member

@yonigozlan yonigozlan left a comment

Choose a reason for hiding this comment

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

Hi @capnmav77 thanks for iterating! Sorry for the delayed review. Almost ready to go, although some logic is missing for segmentation maps

Comment thread src/transformers/models/segformer/image_processing_segformer_fast.py Outdated
Comment thread src/transformers/models/segformer/image_processing_segformer_fast.py Outdated
Comment thread src/transformers/models/segformer/image_processing_segformer_fast.py Outdated
@capnmav77
Copy link
Copy Markdown
Contributor Author

Hi, @yonigozlan , all the tests pass apart from the following :
FAILED tests/models/segformer/test_image_processing_segformer.py::SegformerImageProcessingTest::test_slow_fast_equivalence - AssertionError: False is not true

the tensors from the fast processor does not match the tensor from the slow one ? i've been trying to crack this issue but i'm not getting to the root cause , i assume it's some mishap in the reduce_label function ? or something related to labelling can you suggest fixes ?

slow: 
tensor([[[ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  3,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           3,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  3,  3,  2,  2,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  3,  2,  2,  2,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  3,  3,  3,  3,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  3,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18, 18,  2,  2,  2,  2],
         [ 3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18,  2,  2,  2,  2,  2],
         [ 5,  5,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18,  2,  2,  2,  2,  2],
         [ 5,  5,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18,  2,  2,  2,  2,  2],
         [ 5,  5,  5,  5,  5,  5,  5,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2,  2, 18, 18,  2,  2,  2,  2],
         [ 5,  5,  5,  5,  5,  5,  5,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2, 18, 18, 18,  2,  2,  2,  2],
         [ 5,  5,  5,  5,  5,  5,  5,  1,  1,  0,  0,  0,  2,  2,  2,  2,  2,
           2,  2,  2,  2,  2,  2, 18, 18, 18,  2,  2,  2,  2],
         [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,
           2,  2,  2,  2,  2,  2, 18, 18, 18,  2,  2,  2,  2],
         [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,
          10, 10,  2,  2,  2, 18, 18, 18, 18, 18, 18, 18,  2],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 18, 18, 18, 18, 18, 18],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
         [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
          10, 10, 10, 10, 10, 10, 10, 10,  7,  7,  7,  7,  7 ]]]) - here is the change
 Fast: 
tensor([[[[ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
            3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
            3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
            3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
            3,  3,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
            3,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
            3,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,
            2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  3,  3,  2,  2,
            2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  3,  2,  2,  2,
            2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  2,  2],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  3,  3,  3,  3,  2,  2,  2,  2],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
          [ 3,  3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  2,  2,  4,  4,  2,  2,  2],
          [ 3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  2,  9,  9,  2,  2,  2,  2],
          [ 3,  3,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  3, 14,  8,  2,  2,  2,  2],
          [ 4,  4,  3,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  4, 15,  9,  2,  2,  2,  2],
          [ 5,  5,  4,  3,  3,  3,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  4, 16,  9,  2,  2,  2,  2],
          [ 5,  5,  5,  4,  5,  5,  4,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2,  5, 17, 10,  2,  2,  2,  2],
          [ 5,  5,  5,  5,  5,  5,  5,  3,  2,  2,  2,  2,  2,  2,  2,  2,  2,
            2,  2,  2,  2,  2,  2, 10, 18, 10,  2,  2,  2,  2],
          [ 4,  4,  4,  4,  4,  3,  4,  2,  1,  1,  1,  1,  1,  1,  2,  2,  2,
            2,  2,  2,  2,  2,  4, 14, 18, 10,  2,  2,  2,  2],
          [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,
            2,  2,  2,  2,  2,  8, 18, 18, 12,  3,  2,  2,  2],
          [ 1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  3,  3,  3,  4,  5,
            6,  6,  5,  5,  4, 12, 18, 18, 17, 13, 11, 10,  4],
          [ 6,  7,  8,  8,  8,  8,  8,  9,  9,  8,  8,  9,  9,  9, 10, 10, 10,
           10, 10, 10, 10, 10, 11, 13, 14, 16, 17, 17, 17, 14],
          [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
           10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 12, 12],
          [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
           10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
          [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
           10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,  9],
          [ 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10,
           10, 10, 10, 10, 10, 10,  9,  9,  8,  7,  7,  7,  6 ]]]])
           
           ```

- modified the preprocessing of segmentation maps to use tensors
- added batch support
@ariG23498
Copy link
Copy Markdown
Contributor

Hi @capnmav77 now that the #37005 is merged, you could take a look at the segmentation maps logic. I think that could be of use to you.

@capnmav77
Copy link
Copy Markdown
Contributor Author

capnmav77 commented May 21, 2025

hey @yonigozlan , the image processing fast segformer batched works perfectly but the labels of a single image are not matched , this discrepancy is likely due to inherent differences in the NEAREST interpolation between PIL (used by the slow processor) and TorchVision (used by the fast processor), which can be very difficult to perfectly align. what do you suggest i do ?

out of all the tests , The batched tests pass , but the test_slow_fast_equivalence for a single image which matches labels fails , we can modify the testcase to check for dtype and labels size which pass .

@yonigozlan
Copy link
Copy Markdown
Member

Hey @capnmav77 ! Sorry for the delay. Have you tried with NEAREST_EXACT? It could reduce the differences. If you still have issues we might just increase the tolerance for equivalence tests for this model

@capnmav77
Copy link
Copy Markdown
Contributor Author

Hey @yonigozlan , i've done the required changes and apparantly the maximum difference is 2 hence i've updated the tolerance value to 2.5 in the testcode and all the testcases pass . Let me know if i need to change anything else now ?

@simonreise
Copy link
Copy Markdown
Contributor

simonreise commented Jun 10, 2025

Hi @capnmav77! You should probably implement the same fix as in #38042 , because as far as I can see your current code applies reduce_labels not only to the labels, but also to the images

Copy link
Copy Markdown
Member

@yonigozlan yonigozlan left a comment

Choose a reason for hiding this comment

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

Hey @capnmav77 ! Sorry for the delay. Updated the PR to follow the last fast image processor standards and use modular, will merge once the CI passes!

@yonigozlan yonigozlan enabled auto-merge (squash) July 25, 2025 20:41
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: auto, beit, segformer

@yonigozlan yonigozlan merged commit 4f8f51b into huggingface:main Jul 28, 2025
25 checks passed
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
* Add Fast Segformer Processor

* Modified the params according to segformer model

* modified test_image_processing_Segformer_fast args

- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class

* added segmentation_maps processing logic form the slow segformer processing module with references from beitimageprocessing fast

* fixed code_quality

* added recommended fixes and tests to make sure everything processess smoothly

* Fixed SegmentationMapsLogic

- modified the preprocessing of segmentation maps to use tensors
- added batch support

* fixed some mismatched files

* modified the tolerance for tests

* use modular

* fix ci

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
* Add Fast Segformer Processor

* Modified the params according to segformer model

* modified test_image_processing_Segformer_fast args

- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class

* added segmentation_maps processing logic form the slow segformer processing module with references from beitimageprocessing fast

* fixed code_quality

* added recommended fixes and tests to make sure everything processess smoothly

* Fixed SegmentationMapsLogic

- modified the preprocessing of segmentation maps to use tensors
- added batch support

* fixed some mismatched files

* modified the tolerance for tests

* use modular

* fix ci

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
* Add Fast Segformer Processor

* Modified the params according to segformer model

* modified test_image_processing_Segformer_fast args

- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class

* added segmentation_maps processing logic form the slow segformer processing module with references from beitimageprocessing fast

* fixed code_quality

* added recommended fixes and tests to make sure everything processess smoothly

* Fixed SegmentationMapsLogic

- modified the preprocessing of segmentation maps to use tensors
- added batch support

* fixed some mismatched files

* modified the tolerance for tests

* use modular

* fix ci

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
* Add Fast Segformer Processor

* Modified the params according to segformer model

* modified test_image_processing_Segformer_fast args

- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class

* added segmentation_maps processing logic form the slow segformer processing module with references from beitimageprocessing fast

* fixed code_quality

* added recommended fixes and tests to make sure everything processess smoothly

* Fixed SegmentationMapsLogic

- modified the preprocessing of segmentation maps to use tensors
- added batch support

* fixed some mismatched files

* modified the tolerance for tests

* use modular

* fix ci

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
* Add Fast Segformer Processor

* Modified the params according to segformer model

* modified test_image_processing_Segformer_fast args

- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class

* added segmentation_maps processing logic form the slow segformer processing module with references from beitimageprocessing fast

* fixed code_quality

* added recommended fixes and tests to make sure everything processess smoothly

* Fixed SegmentationMapsLogic

- modified the preprocessing of segmentation maps to use tensors
- added batch support

* fixed some mismatched files

* modified the tolerance for tests

* use modular

* fix ci

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
* Add Fast Segformer Processor

* Modified the params according to segformer model

* modified test_image_processing_Segformer_fast args

- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class

* added segmentation_maps processing logic form the slow segformer processing module with references from beitimageprocessing fast

* fixed code_quality

* added recommended fixes and tests to make sure everything processess smoothly

* Fixed SegmentationMapsLogic

- modified the preprocessing of segmentation maps to use tensors
- added batch support

* fixed some mismatched files

* modified the tolerance for tests

* use modular

* fix ci

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
zaristei pushed a commit to zaristei/transformers that referenced this pull request Sep 9, 2025
* Add Fast Segformer Processor

* Modified the params according to segformer model

* modified test_image_processing_Segformer_fast args

- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class

* added segmentation_maps processing logic form the slow segformer processing module with references from beitimageprocessing fast

* fixed code_quality

* added recommended fixes and tests to make sure everything processess smoothly

* Fixed SegmentationMapsLogic

- modified the preprocessing of segmentation maps to use tensors
- added batch support

* fixed some mismatched files

* modified the tolerance for tests

* use modular

* fix ci

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
snorkelopstesting2-coder pushed a commit to snorkel-marlin-repos/huggingface_transformers_pr_37024_faf590bd-3a4b-4b4c-a2d1-f75157d959c5 that referenced this pull request Oct 11, 2025
Original PR #37024 by capnmav77
Original: huggingface/transformers#37024
snorkelopstesting2-coder added a commit to snorkel-marlin-repos/huggingface_transformers_pr_37024_faf590bd-3a4b-4b4c-a2d1-f75157d959c5 that referenced this pull request Oct 11, 2025
snorkelopstesting2-coder pushed a commit to snorkel-marlin-repos/huggingface_transformers_pr_37024_d323a227-32a6-40b4-b248-6e4bf86c8c42 that referenced this pull request Oct 11, 2025
Original PR #37024 by capnmav77
Original: huggingface/transformers#37024
snorkelopstesting2-coder added a commit to snorkel-marlin-repos/huggingface_transformers_pr_37024_d323a227-32a6-40b4-b248-6e4bf86c8c42 that referenced this pull request Oct 11, 2025
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.

5 participants