Trusted-AI / adversarial-robustness-toolbox

Adversarial Robustness Toolbox (ART) - Python Library for Machine Learning Security - Evasion, Poisoning, Extraction, Inference - Red and Blue Teams
https://adversarial-robustness-toolbox.readthedocs.io/en/latest/
MIT License
4.84k stars 1.16k forks source link

Ability to apply Preprocessor and Postprocessor after Classifier init #374

Closed davidslater closed 4 years ago

davidslater commented 4 years ago

Is your feature request related to a problem? Please describe. Currently, Preprocessor and Postprocessor defenses must be given at Classifier initialization, as they are set during initialization: https://github.com/IBM/adversarial-robustness-toolbox/blob/master/art/classifiers/classifier.py#L124-L132

Describe the solution you'd like Allow these to be set or appended to with seomthing like set_params or append_preprocessing_defense.

Describe alternatives you've considered We have directly modified Classifier.preprocessing_defences and Classifier.postprocessing_defences. This appears safe for the moment, but we would prefer to use an API.

beat-buesser commented 4 years ago

Hi @davidslater I have just remembered that we have already implemented this as part of the new Estimator API for the upcoming ART 1.3 where the new BaseEstimator class and with it all estimators/classifiers in ART 1.3 will have a set_params method for the BaseEstimator's attributes including preprocessing_defences and postprocessing_defences (https://github.com/IBM/adversarial-robustness-toolbox/blob/aceba4222e62b92f1675cc32177fde403b604a24/art/estimators/estimator.py#L73).

Would that work for you?

davidslater commented 4 years ago

I think that this would work. Is there a get_params method as well? That would make it straightforward to append defenses as well:

pre_defenses = estimator.get_params()["preprocessing_defenses"]
pre_defenses.append(new_defense)
estimator.set_params(preprocessing_defenses=pre_defenses)
beat-buesser commented 4 years ago

I think that's a good idea. There is no get_params so far, but we'll add it to BaseEstimator as part of this issue.