art.experimental.estimators
¶
Experimental Estimator API
Base Class JaxEstimator¶
- class art.experimental.estimators.JaxEstimator(**kwargs)¶
Estimator class for Jax models.
- __init__(**kwargs) None ¶
Estimator class for Jax models.
- Parameters
channels_first – Set channels first or last.
clip_values – Tuple of the form (min, max) of floats or np.ndarray representing the minimum and maximum values allowed for features. If floats are provided, these will be used as the range of all features. If arrays are provided, each value will be considered the bound for a feature, thus the shape of clip values needs to match the total number of features.
preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.
postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.
preprocessing – Tuple of the form (subtrahend, divisor) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.
device_type – Type of device on which the classifier is run, either gpu or cpu.
- property channels_first: bool¶
- Returns
Boolean to indicate index of the color channels in the sample x.
- property clip_values: Optional[CLIP_VALUES_TYPE]¶
Return the clip values of the input samples.
- Returns
Clip values (min, max).
- clone_for_refitting() ESTIMATOR_TYPE ¶
Clone estimator for refitting.
- compute_loss(x: ndarray, y: Any, **kwargs) ndarray ¶
Compute the loss of the estimator for samples x.
- Parameters
x (
ndarray
) – Input samples.y – Target values.
- Returns
Loss values.
- Return type
Format as expected by the model
- compute_loss_from_predictions(pred: ndarray, y: ndarray, **kwargs) ndarray ¶
Compute the loss of the estimator for predictions pred.
- Return type
ndarray
- Parameters
pred (
ndarray
) – Model predictions.y (
ndarray
) – Target values.
- Returns
Loss values.
- fit(x: ndarray, y, batch_size: int = 128, nb_epochs: int = 20, **kwargs) None ¶
Fit the model of the estimator on the training data x and y.
- 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 (Format as expected by the model) – Target values.
batch_size (
int
) – Batch size.nb_epochs (
int
) – Number of training epochs.
- fit_generator(generator: DataGenerator, nb_epochs: int = 20, **kwargs) None ¶
Fit the estimator using a generator yielding training batches. Implementations can provide framework-specific versions of this function to speed-up computation.
- Parameters
generator – Batch generator providing (x, y) for each epoch.
nb_epochs (
int
) – Number of training epochs.
- abstract get_activations(x: ndarray, layer: Union[int, str], batch_size: int, framework: bool = False) ndarray ¶
Return the output of a specific layer for samples x where layer is the index of the layer between 0 and nb_layers - 1 or the name of the layer. The number of layers can be determined by counting the results returned by calling `layer_names.
- Return type
ndarray
- Parameters
x (
ndarray
) – Sampleslayer – Index or name of the layer.
batch_size (
int
) – Batch size.framework (
bool
) – If true, return the intermediate tensor representation of the activation.
- Returns
The output of layer, where the first dimension is the batch size corresponding to x.
- get_params() Dict[str, Any] ¶
Get all parameters and their values of this estimator.
- Returns
A dictionary of string parameter names to their value.
- abstract property input_shape: Tuple[int, ...]¶
Return the shape of one input sample.
- Returns
Shape of one input sample.
- property layer_names: Optional[List[str]]¶
Return the names of the hidden layers in the model, if applicable.
- Returns
The names of the hidden layers in the model, input and output layers are ignored.
Warning
layer_names tries to infer the internal structure of the model. This feature comes with no guarantees on the correctness of the result. The intended order of the layers tries to match their order in the model, but this is not guaranteed either.
- abstract loss_gradient(x, y, **kwargs)¶
Compute the gradient of the loss function w.r.t. x.
- Parameters
x (Format as expected by the model) – Samples.
y (Format as expected by the model) – Target values.
- Returns
Loss gradients w.r.t. x in the same format as x.
- Return type
Format as expected by the model
- property model¶
Return the model.
- Returns
The model.
- predict(x: ndarray, batch_size: int = 128, **kwargs)¶
Perform prediction 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).batch_size (
int
) – Batch size.
- Returns
Predictions.
- Return type
Format as expected by the model
- set_params(**kwargs) None ¶
Take a dictionary of parameters and apply checks before setting them as attributes.
- Parameters
kwargs – A dictionary of attributes.