Add Fast Segformer Processor#37024
Conversation
|
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 |
- removed redundant params like do_center_crop,center_crop which aren't present in the original segformer class
yonigozlan
left a comment
There was a problem hiding this comment.
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
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 |
yonigozlan
left a comment
There was a problem hiding this comment.
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.pyYou 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.
|
Hey @yonigozlan , i have modified the code accordingly but there's a issue i'm not able to figure out , one local test fails : 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 : |
yonigozlan
left a comment
There was a problem hiding this comment.
Hi @capnmav77 thanks for iterating! Sorry for the delayed review. Almost ready to go, although some logic is missing for segmentation maps
|
Hi, @yonigozlan , all the tests pass apart from the following : 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 ? |
- modified the preprocessing of segmentation maps to use tensors - added batch support
|
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. |
|
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 . |
|
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 |
|
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 ? |
|
Hi @capnmav77! You should probably implement the same fix as in #38042 , because as far as I can see your current code applies |
yonigozlan
left a comment
There was a problem hiding this comment.
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!
|
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. |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto, beit, segformer |
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
Original PR #37024 by capnmav77 Original: huggingface/transformers#37024
Merged from original PR #37024 Original: huggingface/transformers#37024
Original PR #37024 by capnmav77 Original: huggingface/transformers#37024
Merged from original PR #37024 Original: huggingface/transformers#37024
What does this PR do?
Linked: #36978
Adding fast processor for Segformer.
CC: @yonigozlan