Skip to content

Commit eb1f1cf

Browse files
authored
Merge branch 'dev_1.8.0' into development_issue_1196
2 parents 8271c09 + 58839f7 commit eb1f1cf

25 files changed

+57
-713
lines changed

art/classifiers/__init__.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

art/classifiers/scikitlearn/__init__.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

art/estimators/classification/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from art.estimators.classification.lightgbm import LightGBMClassifier
1717
from art.estimators.classification.mxnet import MXClassifier
1818
from art.estimators.classification.pytorch import PyTorchClassifier
19+
from art.estimators.classification.query_efficient_bb import QueryEfficientGradientEstimationClassifier
1920
from art.estimators.classification.scikitlearn import SklearnClassifier
2021
from art.estimators.classification.tensorflow import (
2122
TFClassifier,

art/estimators/classification/blackbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
class BlackBoxClassifier(ClassifierMixin, BaseEstimator):
4141
"""
42-
Wrapper class for black-box classifiers.
42+
Class for black-box classifiers.
4343
"""
4444

4545
estimator_params = Classifier.estimator_params + ["nb_classes", "input_shape", "predict_fn"]
@@ -163,7 +163,7 @@ def save(self, filename: str, path: Optional[str] = None) -> None:
163163

164164
class BlackBoxClassifierNeuralNetwork(NeuralNetworkMixin, ClassifierMixin, BaseEstimator):
165165
"""
166-
Wrapper class for black-box neural network classifiers.
166+
Class for black-box neural network classifiers.
167167
"""
168168

169169
estimator_params = (

art/estimators/classification/catboost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
class CatBoostARTClassifier(ClassifierDecisionTree):
4545
"""
46-
Wrapper class for importing CatBoost models.
46+
Class for importing CatBoost models.
4747
"""
4848

4949
estimator_params = ClassifierDecisionTree.estimator_params + ["nb_features"]

art/estimators/classification/detector_classifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def loss_gradient( # pylint: disable=W0221
284284
def layer_names(self) -> List[str]:
285285
"""
286286
Return the hidden layers in the model, if applicable. This function is not supported for the
287-
Classifier and Detector wrapper.
287+
Classifier and Detector classes.
288288
289289
:return: The hidden layers in the model, input and output layers excluded.
290290
:raises `NotImplementedException`: This method is not supported for detector-classifiers.

art/estimators/classification/lightgbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
class LightGBMClassifier(ClassifierDecisionTree):
4747
"""
48-
Wrapper class for importing LightGBM models.
48+
Class for importing LightGBM models.
4949
"""
5050

5151
def __init__(

art/estimators/classification/mxnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
class MXClassifier(ClassGradientsMixin, ClassifierMixin, MXEstimator): # lgtm [py/missing-call-to-init]
4848
"""
49-
Wrapper class for importing MXNet Gluon models.
49+
Class for importing MXNet Gluon models.
5050
"""
5151

5252
estimator_params = (

art/wrappers/query_efficient_bb.py renamed to art/estimators/classification/query_efficient_bb.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,31 @@
1818
"""
1919
Provides black-box gradient estimation using NES.
2020
"""
21-
from __future__ import absolute_import, division, print_function, unicode_literals
22-
2321
import logging
2422
from typing import List, Optional, Tuple, Union, TYPE_CHECKING
2523

2624
import numpy as np
2725
from scipy.stats import entropy
2826

29-
from art.estimators.classification.classifier import ClassifierClassLossGradients
30-
from art.utils import clip_and_round, deprecated
31-
from art.wrappers.wrapper import ClassifierWrapper
27+
from art.estimators.estimator import BaseEstimator
28+
from art.estimators.classification.classifier import ClassifierMixin, ClassifierLossGradients
29+
from art.utils import clip_and_round
3230

3331
if TYPE_CHECKING:
3432
from art.utils import CLASSIFIER_CLASS_LOSS_GRADIENTS_TYPE
3533

3634
logger = logging.getLogger(__name__)
3735

3836

39-
@deprecated(
40-
end_version="1.8.0",
41-
reason="Expectation over transformation has been replaced with " "art.estimators",
42-
replaced_by="art.preprocessing.expectation_over_transformation",
43-
)
44-
class QueryEfficientBBGradientEstimation(ClassifierWrapper, ClassifierClassLossGradients):
37+
class QueryEfficientGradientEstimationClassifier(ClassifierLossGradients, ClassifierMixin, BaseEstimator):
4538
"""
4639
Implementation of Query-Efficient Black-box Adversarial Examples. The attack approximates the gradient by
4740
maximizing the loss function over samples drawn from random Gaussian noise around the input.
4841
4942
| Paper link: https://arxiv.org/abs/1712.07113
5043
"""
5144

52-
attack_params = ["num_basis", "sigma", "round_samples"]
45+
estimator_params = ["num_basis", "sigma", "round_samples"]
5346

5447
def __init__(
5548
self,
@@ -59,20 +52,19 @@ def __init__(
5952
round_samples: float = 0.0,
6053
) -> None:
6154
"""
62-
:param classifier: An instance of a `Classifier` whose loss_gradient is being approximated.
55+
:param classifier: An instance of a classification estimator whose loss_gradient is being approximated.
6356
:param num_basis: The number of samples to draw to approximate the gradient.
6457
:param sigma: Scaling on the Gaussian noise N(0,1).
6558
:param round_samples: The resolution of the input domain to round the data to, e.g., 1.0, or 1/255. Set to 0 to
6659
disable.
6760
"""
68-
super().__init__(classifier)
69-
# self.predict refers to predict of classifier
61+
super().__init__(model=classifier.model, clip_values=classifier.clip_values)
7062
# pylint: disable=E0203
71-
self._predict = self.classifier.predict
63+
self._classifier = classifier
7264
self.num_basis = num_basis
7365
self.sigma = sigma
7466
self.round_samples = round_samples
75-
self._nb_classes = self.classifier.nb_classes
67+
self._nb_classes = self._classifier.nb_classes
7668

7769
@property
7870
def input_shape(self) -> Tuple[int, ...]:
@@ -81,18 +73,18 @@ def input_shape(self) -> Tuple[int, ...]:
8173
8274
:return: Shape of one input sample.
8375
"""
84-
return self._input_shape # type: ignore
76+
return self._classifier.input_shape # type: ignore
8577

8678
def predict(self, x: np.ndarray, batch_size: int = 128, **kwargs) -> np.ndarray: # pylint: disable=W0221
8779
"""
88-
Perform prediction of the classifier for input `x`.
80+
Perform prediction of the classifier for input `x`. Rounds results first.
8981
9082
:param x: Features in array of shape (nb_samples, nb_features) or (nb_samples, nb_pixels_1, nb_pixels_2,
9183
nb_channels) or (nb_samples, nb_channels, nb_pixels_1, nb_pixels_2).
9284
:param batch_size: Size of batches.
9385
:return: Array of predictions of shape `(nb_inputs, nb_classes)`.
9486
"""
95-
return self._wrap_predict(x, batch_size=batch_size)
87+
return self._classifier.predict(clip_and_round(x, self.clip_values, self.round_samples), batch_size=batch_size)
9688

9789
def fit(self, x: np.ndarray, y: np.ndarray, **kwargs) -> None:
9890
"""
@@ -172,16 +164,6 @@ def loss_gradient(self, x: np.ndarray, y: np.ndarray, **kwargs) -> np.ndarray:
172164
grads = self._apply_preprocessing_gradient(x, np.array(grads))
173165
return grads
174166

175-
def _wrap_predict(self, x: np.ndarray, batch_size: int = 128) -> np.ndarray:
176-
"""
177-
Perform prediction for a batch of inputs. Rounds results first.
178-
179-
:param x: Input samples.
180-
:param batch_size: Size of batches.
181-
:return: Array of predictions of shape `(nb_inputs, nb_classes)`.
182-
"""
183-
return self._predict(clip_and_round(x, self.clip_values, self.round_samples), **{"batch_size": batch_size})
184-
185167
def get_activations(self, x: np.ndarray, layer: Union[int, str], batch_size: int) -> np.ndarray:
186168
"""
187169
Return the output of the specified layer for input `x`. `layer` is specified by layer index (between 0 and

art/estimators/classification/scikitlearn.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def SklearnClassifier(
6262
) -> "ScikitlearnClassifier":
6363
"""
6464
Create a `Classifier` instance from a scikit-learn Classifier model. This is a convenience function that
65-
instantiates the correct wrapper class for the given scikit-learn model.
65+
instantiates the correct class for the given scikit-learn model.
6666
6767
:param model: scikit-learn Classifier model.
6868
:param clip_values: Tuple of the form `(min, max)` representing the minimum and maximum values allowed
@@ -100,7 +100,7 @@ def SklearnClassifier(
100100

101101
class ScikitlearnClassifier(ClassifierMixin, ScikitlearnEstimator): # lgtm [py/missing-call-to-init]
102102
"""
103-
Wrapper class for scikit-learn classifier models.
103+
Class for scikit-learn classifier models.
104104
"""
105105

106106
estimator_params = ClassifierMixin.estimator_params + ScikitlearnEstimator.estimator_params + ["use_logits"]
@@ -284,7 +284,7 @@ def _get_nb_classes(self) -> int:
284284

285285
class ScikitlearnDecisionTreeClassifier(ScikitlearnClassifier):
286286
"""
287-
Wrapper class for scikit-learn Decision Tree Classifier models.
287+
Class for scikit-learn Decision Tree Classifier models.
288288
"""
289289

290290
def __init__(
@@ -430,7 +430,7 @@ def _get_leaf_nodes(self, node_id, i_tree, class_label, box) -> List["LeafNode"]
430430

431431
class ScikitlearnDecisionTreeRegressor(ScikitlearnDecisionTreeClassifier):
432432
"""
433-
Wrapper class for scikit-learn Decision Tree Regressor models.
433+
Class for scikit-learn Decision Tree Regressor models.
434434
"""
435435

436436
def __init__(
@@ -520,7 +520,7 @@ def _get_leaf_nodes(self, node_id, i_tree, class_label, box) -> List["LeafNode"]
520520

521521
class ScikitlearnExtraTreeClassifier(ScikitlearnDecisionTreeClassifier):
522522
"""
523-
Wrapper class for scikit-learn Extra TreeClassifier Classifier models.
523+
Class for scikit-learn Extra TreeClassifier Classifier models.
524524
"""
525525

526526
def __init__(
@@ -559,7 +559,7 @@ def __init__(
559559

560560
class ScikitlearnAdaBoostClassifier(ScikitlearnClassifier):
561561
"""
562-
Wrapper class for scikit-learn AdaBoost Classifier models.
562+
Class for scikit-learn AdaBoost Classifier models.
563563
"""
564564

565565
def __init__(
@@ -598,7 +598,7 @@ def __init__(
598598

599599
class ScikitlearnBaggingClassifier(ScikitlearnClassifier):
600600
"""
601-
Wrapper class for scikit-learn Bagging Classifier models.
601+
Class for scikit-learn Bagging Classifier models.
602602
"""
603603

604604
def __init__(
@@ -638,7 +638,7 @@ def __init__(
638638

639639
class ScikitlearnExtraTreesClassifier(ScikitlearnClassifier, DecisionTreeMixin):
640640
"""
641-
Wrapper class for scikit-learn Extra Trees Classifier models.
641+
Class for scikit-learn Extra Trees Classifier models.
642642
"""
643643

644644
def __init__(
@@ -711,7 +711,7 @@ def get_trees(self) -> List["Tree"]: # lgtm [py/similar-function]
711711

712712
class ScikitlearnGradientBoostingClassifier(ScikitlearnClassifier, DecisionTreeMixin):
713713
"""
714-
Wrapper class for scikit-learn Gradient Boosting Classifier models.
714+
Class for scikit-learn Gradient Boosting Classifier models.
715715
"""
716716

717717
def __init__(
@@ -785,7 +785,7 @@ def get_trees(self) -> List["Tree"]:
785785

786786
class ScikitlearnRandomForestClassifier(ScikitlearnClassifier):
787787
"""
788-
Wrapper class for scikit-learn Random Forest Classifier models.
788+
Class for scikit-learn Random Forest Classifier models.
789789
"""
790790

791791
def __init__(
@@ -858,7 +858,7 @@ def get_trees(self) -> List["Tree"]: # lgtm [py/similar-function]
858858

859859
class ScikitlearnLogisticRegression(ClassGradientsMixin, LossGradientsMixin, ScikitlearnClassifier):
860860
"""
861-
Wrapper class for scikit-learn Logistic Regression models.
861+
Class for scikit-learn Logistic Regression models.
862862
"""
863863

864864
def __init__(
@@ -1045,7 +1045,7 @@ def get_trainable_attribute_names() -> Tuple[str, str]:
10451045

10461046
class ScikitlearnGaussianNB(ScikitlearnClassifier):
10471047
"""
1048-
Wrapper class for scikit-learn Gaussian Naive Bayes models.
1048+
Class for scikit-learn Gaussian Naive Bayes models.
10491049
"""
10501050

10511051
def __init__(
@@ -1094,7 +1094,7 @@ def get_trainable_attribute_names() -> Tuple[str, str]:
10941094

10951095
class ScikitlearnSVC(ClassGradientsMixin, LossGradientsMixin, ScikitlearnClassifier):
10961096
"""
1097-
Wrapper class for scikit-learn C-Support Vector Classification models.
1097+
Class for scikit-learn C-Support Vector Classification models.
10981098
"""
10991099

11001100
def __init__(

0 commit comments

Comments
 (0)