-
Notifications
You must be signed in to change notification settings - Fork 0
Modality-aware composer #126
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
Conversation
This reverts commit cb29cde.
dxoigmn
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.
See comments.
mart/attack/composer.py
Outdated
| __all__ = ["Additive", "Overlay", "ModalityComposer"] | ||
|
|
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 don't know if exporting these is smart given their generic names? I wouldn't mind exporting (by default) ModalityComposer though. If they were named AdditiveComposer then the possibility of a naming conflict is low. But mart.attack.Additive feels a little too generic?
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.
Agree. Removed.
mart/attack/composer.py
Outdated
| **kwargs, | ||
| ) -> torch.Tensor | tuple: | ||
| # Bypass batch-aware in Composer.__call__(), because we have the recursive self.compose(). | ||
| input_adv = self.compose(perturbation, input=input, target=target) |
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 would expect, at a minimum, that these arguments (perturbation, input, and target) would have the same types as in compose since you're directly passing them to compose?
My suspicion is that some functionality probably needs to move to Composer.__call__ while dict functionality should be in ModalityComposer.__call__?
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 feel like it will be less confusing if we follow the implementation in Enforcer.
mart/attack/composer.py
Outdated
| class ModalityComposer(Composer): | ||
| """A modality-aware composer. | ||
| Example usage: `ModalityComposer(rgb=Overlay(), depth=Additive())`. Note that | ||
| `ModalityComposer(default=Additive())` is equivalent with `Additive()`. | ||
| """ | ||
|
|
||
| def __init__(self, **modality_composers): | ||
| self.modality_composers = modality_composers | ||
|
|
||
| def __call__( | ||
| self, | ||
| perturbation: torch.Tensor | tuple, | ||
| *, | ||
| input: torch.Tensor | tuple, | ||
| target: torch.Tensor | dict[str, Any] | tuple, | ||
| **kwargs, |
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.
ModalityComposer feels like it can just wholesale replace Composer? If so, you should just rename this as Composer and get rid of ModalityComposer. The other option is to just have ModalityComposer only take dicts so that it specialized in modalities, which we encode as dicts (as the name suggests).
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 revised the implementation following the structure in Enforcer.
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.
Maybe we shouldn't merge this PR.
I will try to implement a shared modality-aware mechanism in Perturber for initializer gradient_modifier projector composer and optim_params.
|
Abandoned in favor of #115 |
What does this PR do?
This PR adds a modality-aware composer
Composer.Type of change
Please check all relevant options.
Testing
Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.
pytest tests/test_composer.pyBefore submitting
pre-commit run -acommand without errorsDid you have fun?
Make sure you had fun coding 🙃