art.defences.detector.evasion.subsetscanning

This module implements the fast generalized subset scan based detector.

Subset Scanning Detector

class art.defences.detector.evasion.subsetscanning.SubsetScanningDetector(classifier: art.estimators.classification.classifier.ClassifierNeuralNetwork, bgd_data: numpy.ndarray, layer: Union[int, str])

Fast generalized subset scan based detector by McFowland, E., Speakman, S., and Neill, D. B. (2013).

calculate_pvalue_ranges(eval_x: numpy.ndarray) → numpy.ndarray

Returns computed p-value ranges.

Return type

ndarray

Parameters

eval_x (ndarray) – Data being evaluated for anomalies.

Returns

P-value ranges.

property channel_index
Returns

Index of the axis containing the color channels in the samples x.

property channels_first
Returns

Boolean to indicate index of the color channels in the sample x.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the detector using training data. Assumes that the classifier is already trained.

Raises

NotImplementedException – This method is not supported for detectors.

fit_generator(generator: DataGenerator, nb_epochs: int = 20, **kwargs) → None

Fit the classifier using the generator gen that yields batches as specified. This function is not supported for this detector.

Raises

NotImplementedException – This method is not supported for detectors.

get_activations(*args, **kwargs)

Return the output of the specified layer for input x. layer is specified by layer index (between 0 and nb_layers - 1) or by name. The number of layers can be determined by counting the results returned by calling layer_names. This function is not supported for this detector.

Raises

NotImplementedException – This method is not supported for detectors.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property learning_phase

The learning phase set by the user. Possible values are True for training or False for prediction and None if it has not been set by the library. In the latter case, the library does not do any explicit learning phase manipulation and the current value of the backend framework is used. If a value has been set by the user for this property, it will impact all following computations for model fitting, prediction and gradients.

Returns

Learning phase.

loss(x: numpy.ndarray, y: numpy.ndarray, **kwargs) → numpy.ndarray

Compute the loss of the neural network for samples x.

Parameters
  • x (ndarray) – Samples of shape (nb_samples, nb_features) or (nb_samples, nb_pixels_1, nb_pixels_2, nb_channels) or (nb_samples, nb_channels, nb_pixels_1, nb_pixels_2).

  • y (ndarray) – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape (nb_samples,).

Returns

Loss values.

Return type

Format as expected by the model

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform detection of adversarial data and return prediction as tuple.

Raises

NotImplementedException – This method is not supported for detectors.

save(filename: str, path: Optional[str] = None) → None

Save a model to file in the format specific to the backend framework. This function is not supported for ensembles.

Parameters
  • filename (str) – Name of the file where to store the model.

  • path – Path of the folder where to store the model. If no path is specified, the model will be stored in the default data location of the library ART_DATA_PATH.

scan(clean_x: numpy.ndarray, adv_x: numpy.ndarray, clean_size: Optional[int] = None, advs_size: Optional[int] = None, run: int = 10) → Tuple[list, list, float]

Returns scores of highest scoring subsets.

Return type

Tuple

Parameters
  • clean_x (ndarray) – Data presumably without anomalies.

  • adv_x (ndarray) – Data presumably with anomalies (adversarial samples).

  • clean_size

  • advs_size

  • run (int) –

Returns

(clean_scores, adv_scores, detectionpower).

set_learning_phase(train: bool) → None

Set the learning phase for the backend framework.

Parameters

train (bool) – True if the learning phase is training, otherwise False.