-
Notifications
You must be signed in to change notification settings - Fork 0
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
MART typing #29
MART typing #29
Conversation
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/adversary.py
Outdated
def on_run_start(self, adversary, input, target, model, **kwargs): | ||
def on_run_start( | ||
self, | ||
adversary: Callback, |
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 think we would want to type this as Adversary
?
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.
The Adversary
class is defined below in this file, so I decided to use its parent class. Other option is to type it as torch.nn.Module
which is the other parent class.
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 still think it should be Adversary
rather than nn.Module
. It definitely should not be Callback
. What is the problem with using Adversary
? Is it because circular imports? Then we should restructure things. (Or make this nn.Module
and create a new PR that fixes the circular import issue.)
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.
Created issue #38 to tackle this. This circular issue can be a sign of a possible design problem between the adversaries and callbacks.
mart/attack/adversary_in_art.py
Outdated
def __init__(self, target_model, mart_exp_config_yaml, **kwargs): | ||
def __init__(self, target_model: torch.nn.Module, mart_exp_config_yaml: str, **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.
I think this class should adopt the types in https://github.com/Trusted-AI/adversarial-robustness-toolbox/blob/987052c405e05d458276299aafc7d47bb584e738/art/estimators/object_detection/object_detector.py#L42
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.
Should we use the ART's ObjectDetector
type in the target_model
argument?
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.
Yeah I think that is correct. @mzweilin?
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.
Currently, we expect it to be ObjectDetector
. But later we may want to use BaseEstimator
as we generalize the wrapper for non-object detection models in ART.
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/adversary.py
Outdated
def on_run_start(self, adversary, input, target, model, **kwargs): | ||
def on_run_start( | ||
self, | ||
adversary: Callback, |
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 still think it should be Adversary
rather than nn.Module
. It definitely should not be Callback
. What is the problem with using Adversary
? Is it because circular imports? Then we should restructure things. (Or make this nn.Module
and create a new PR that fixes the circular import issue.)
mart/attack/adversary_in_art.py
Outdated
def __init__(self, target_model, mart_exp_config_yaml, **kwargs): | ||
def __init__(self, target_model: torch.nn.Module, mart_exp_config_yaml: str, **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.
Yeah I think that is correct. @mzweilin?
mart/attack/callbacks/base.py
Outdated
def on_run_start(self, adversary, input, target, model, **kwargs): | ||
def on_run_start( | ||
self, | ||
adversary: torch.nn.Module, |
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.
Okay.
* Removed typing hints to the AdversaryCallbackHookMixin class, since the base class already documents it.
afad315
to
2a9c668
Compare
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.
One comment about using typing.TYPE_CHECKING
to guard new imports.
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.
LGTM!
What does this PR do?
Add typing annotation to the MART implementation to make the code more readable and robust.
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 --cov=mart
Before submitting
pre-commit run -a
command without errorsDid you have fun?
Make sure you had fun coding 🙃