uniformize kwargs for SAM#34578
Conversation
5c2efda to
197e079
Compare
SangbumChoi
left a comment
There was a problem hiding this comment.
I appreciate this PR since I am working on SAM2. It seems nice :)
There was a problem hiding this comment.
Can we also define the input time in audio and video?
There was a problem hiding this comment.
I don't understand what you mean here, could you please be more specific?
The signature of __call__ is given, it should not be extended as far as I understand. However, it can be added as part of VideosKwargs and/or AudioKwargs. Can you point me where this attribute/variable is defined?
There was a problem hiding this comment.
*time -> *type, I think it is okay since this does not requires audio and video
There was a problem hiding this comment.
I think it this segmentation_maps is not required for the inference of SAM.
There was a problem hiding this comment.
This is needed for backwards compatibility - even if it is not used. E.g. take the following call: processor(images, None, input_points). If I would remove it from _add_args_for_backward_compatibility, such calls would break.
If I understood correctly, #31911 is about uniform kwargs, and then at a later step the API would be cleaned up further. In SAM's case, _add_args_for_backward_compatibility will be removed, and then segmentation_maps can be removed as well.
There was a problem hiding this comment.
We actually have an existing way to handle such positional args, you can take a look at udop processor for example :)
There was a problem hiding this comment.
Is there reason for the existance of this *args?
There was a problem hiding this comment.
Yes, see comment above. Purely for bc and should be removed at a later stage.
|
cc @yonigozlan can you take a look! |
yonigozlan
left a comment
There was a problem hiding this comment.
Thanks a lot for working on this!
Looks great to me overall, only thing is to use the existing methods to handle positional args for backward compatibility.
On a separate note, and I know this precedes this PR, but it looks to me that there is only an image processor in this processor? Why was all this logic created as a processor at all and not just added to an image processor?
If anyone has any explanation for that, I’d really appreciate it. :)
There was a problem hiding this comment.
These should be added to the optional_call_args attribute (see udop processor)
There was a problem hiding this comment.
This won't be needed as we now have prepare_and_validate_optional_call_args
There was a problem hiding this comment.
| *args, # to be deprecated | |
| # The following is to capture `segmentation_maps`, `input_points`, `input_labels` and `input_boxes` arguments that may be passed as a positional argument. | |
| # See transformers.processing_utils.ProcessorMixin.prepare_and_validate_optional_call_args for more details, | |
| # or this conversation for more context: https://github.com/huggingface/transformers/pull/32544#discussion_r1720208116 | |
| # This behavior is only needed for backward compatibility and will be removed in future versions. | |
| # | |
| *args, |
There was a problem hiding this comment.
| **self._add_args_for_backward_compatibility(args), | |
| **self.prepare_and_validate_optional_call_args(*args), |
|
@yonigozlan Thanks for the review, I have implemented your suggestions. Could you check again please? |
|
Friendly reminder @yonigozlan |
yonigozlan
left a comment
There was a problem hiding this comment.
Looks good to me, thanks for iterating!
Last step is to add the ProcessorTesterMixin to SamProcessorTest in test_processor_sam.py, and make sure all the tests pass. Since the processor really only process images, there will probably be quite a few tests to override.
And also you'' have to rebase on main!
67d3d6b to
3dc8b92
Compare
3dc8b92 to
d92cd4b
Compare
yonigozlan
left a comment
There was a problem hiding this comment.
Left two small comments and after these modifications LGTM! Thanks for working on this
| @require_vision | ||
| @require_tf | ||
| class TFSamProcessorTest(unittest.TestCase): | ||
| class TFSamProcessorTest(ProcessorTesterMixin, unittest.TestCase): |
There was a problem hiding this comment.
I'd say you only need ProcessorTesterMixin for SamProcessorTest, so you can remove this here and the skipped tests as well
There was a problem hiding this comment.
Makes sense. However, I had to then add back the prepare_image_inputs methods. With this, I updated the comment.
| @require_vision | ||
| @require_torchvision | ||
| class SamProcessorEquivalenceTest(unittest.TestCase): | ||
| class SamProcessorEquivalenceTest(ProcessorTesterMixin, unittest.TestCase): |
|
Pinging @ArthurZucker for a core maintainer review |
|
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. |
a7c143d to
6f24d6c
Compare
ArthurZucker
left a comment
There was a problem hiding this comment.
Thanks @yonigozlan for the reviews! 🤗
Adds uniformized processors for SAM following #31911.
@qubvel @molbap