nsl.configs.make_adv_reg_config
Stay organized with collections
Save and categorize content based on your preferences.
Creates an nsl.configs.AdvRegConfig
object.
nsl.configs.make_adv_reg_config(
multiplier=attr.fields(AdvRegConfig).multiplier.default,
feature_mask=attr.fields(AdvNeighborConfig).feature_mask.default,
adv_step_size=attr.fields(AdvNeighborConfig).adv_step_size.default,
adv_grad_norm=attr.fields(AdvNeighborConfig).adv_grad_norm.default,
clip_value_min=attr.fields(AdvNeighborConfig).clip_value_min.default,
clip_value_max=attr.fields(AdvNeighborConfig).clip_value_max.default,
pgd_iterations=attr.fields(AdvNeighborConfig).pgd_iterations.default,
pgd_epsilon=attr.fields(AdvNeighborConfig).pgd_epsilon.default,
random_init=attr.fields(AdvNeighborConfig).random_init.default
)
Used in the notebooks
Args |
multiplier
|
multiplier to adversarial regularization loss. Defaults to 0.2.
|
feature_mask
|
mask w/ values in [0, 1] applied on the gradient. Its shape
should be the same as (or broadcastable to) that of the input features.
If the input features are in a collection (e.g. list or dictionary), this
field should also be a collection of the same structure. Input features
corresponding to mask values of 0.0 are not perturbed. Setting this
field to None is equivalent to setting a mask value of 1.0 for all input
features.
|
adv_step_size
|
step size to find the adversarial sample. Defaults to 0.001.
|
adv_grad_norm
|
type of tensor norm to normalize the gradient. Input will be
converted to NormType when applicable (e.g., a value of 'l2' will be
converted to nsl.configs.NormType.L2 ). Defaults to L2 norm.
|
clip_value_min
|
minimum value to clip the features after perturbation. The
shape should be the same as (or broadcastable to) input features. If the
input features are in a collection (e.g. list or dictionary), this field
should also be a collection with the same structure. An omitted or
None -valued entry in the collection indicates no constraint on the
corresponding feature.
|
clip_value_max
|
maximum value to clip the feature after perturbation. (See
clip_value_min for the structure and shape limitations.)
|
pgd_iterations
|
number of attack iterations for Projected Gradient Descent
(PGD) attack. Defaults to 1, which resembles the Fast Gradient Sign Method
(FGSM) attack.
|
pgd_epsilon
|
radius of the epsilon ball to project back to. Only used in
Projected Gradient Descent (PGD) attack.
|
random_init
|
Apply a random perturbation before FGSM/PGD steps. Default set
to False for no random initialization being applied.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-10-28 UTC.
[null,null,["Last updated 2022-10-28 UTC."],[],[],null,["# nsl.configs.make_adv_reg_config\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/neural-structured-learning/blob/v1.4.0/neural_structured_learning/configs/configs.py#L94-L148) |\n\nCreates an [`nsl.configs.AdvRegConfig`](../../nsl/configs/AdvRegConfig) object. \n\n nsl.configs.make_adv_reg_config(\n multiplier=attr.fields(AdvRegConfig).multiplier.default,\n feature_mask=attr.fields(AdvNeighborConfig).feature_mask.default,\n adv_step_size=attr.fields(AdvNeighborConfig).adv_step_size.default,\n adv_grad_norm=attr.fields(AdvNeighborConfig).adv_grad_norm.default,\n clip_value_min=attr.fields(AdvNeighborConfig).clip_value_min.default,\n clip_value_max=attr.fields(AdvNeighborConfig).clip_value_max.default,\n pgd_iterations=attr.fields(AdvNeighborConfig).pgd_iterations.default,\n pgd_epsilon=attr.fields(AdvNeighborConfig).pgd_epsilon.default,\n random_init=attr.fields(AdvNeighborConfig).random_init.default\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Adversarial regularization for image classification](https://www.tensorflow.org/neural_structured_learning/tutorials/adversarial_keras_cnn_mnist) |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `multiplier` | multiplier to adversarial regularization loss. Defaults to 0.2. |\n| `feature_mask` | mask w/ values in `[0, 1]` applied on the gradient. Its shape should be the same as (or broadcastable to) that of the input features. If the input features are in a collection (e.g. list or dictionary), this field should also be a collection of the same structure. Input features corresponding to mask values of 0.0 are *not* perturbed. Setting this field to `None` is equivalent to setting a mask value of 1.0 for all input features. |\n| `adv_step_size` | step size to find the adversarial sample. Defaults to 0.001. |\n| `adv_grad_norm` | type of tensor norm to normalize the gradient. Input will be converted to `NormType` when applicable (e.g., a value of 'l2' will be converted to [`nsl.configs.NormType.L2`](../../nsl/configs/NormType#L2)). Defaults to L2 norm. |\n| `clip_value_min` | minimum value to clip the features after perturbation. The shape should be the same as (or broadcastable to) input features. If the input features are in a collection (e.g. list or dictionary), this field should also be a collection with the same structure. An omitted or `None`-valued entry in the collection indicates no constraint on the corresponding feature. |\n| `clip_value_max` | maximum value to clip the feature after perturbation. (See `clip_value_min` for the structure and shape limitations.) |\n| `pgd_iterations` | number of attack iterations for Projected Gradient Descent (PGD) attack. Defaults to 1, which resembles the Fast Gradient Sign Method (FGSM) attack. |\n| `pgd_epsilon` | radius of the epsilon ball to project back to. Only used in Projected Gradient Descent (PGD) attack. |\n| `random_init` | Apply a random perturbation before FGSM/PGD steps. Default set to `False` for no random initialization being applied. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| An [`nsl.configs.AdvRegConfig`](../../nsl/configs/AdvRegConfig) object. ||\n\n\u003cbr /\u003e"]]