@@ -70,9 +70,6 @@ class DefenseEvaluate: | |||||
Returns: | Returns: | ||||
float, the higher, the more successful the defense is. | float, the higher, the more successful the defense is. | ||||
Examples: | |||||
>>> def_eval.cav() | |||||
""" | """ | ||||
def_succ_num = np.sum(np.argmax(self._def_preds, axis=1) | def_succ_num = np.sum(np.argmax(self._def_preds, axis=1) | ||||
== self._true_labels) | == self._true_labels) | ||||
@@ -87,9 +84,6 @@ class DefenseEvaluate: | |||||
Returns: | Returns: | ||||
float, the higher, the more successful the defense is. | float, the higher, the more successful the defense is. | ||||
Examples: | |||||
>>> def_eval.crr() | |||||
""" | """ | ||||
cond1 = np.argmax(self._def_preds, axis=1) == self._true_labels | cond1 = np.argmax(self._def_preds, axis=1) == self._true_labels | ||||
cond2 = np.argmax(self._raw_preds, axis=1) != self._true_labels | cond2 = np.argmax(self._raw_preds, axis=1) != self._true_labels | ||||
@@ -118,9 +112,6 @@ class DefenseEvaluate: | |||||
- float, the lower, the more successful the defense is. | - float, the lower, the more successful the defense is. | ||||
- If return value == -1, len(idxes) == 0. | - If return value == -1, len(idxes) == 0. | ||||
Examples: | |||||
>>> def_eval.ccv() | |||||
""" | """ | ||||
idxes = np.arange(self._num_samples) | idxes = np.arange(self._num_samples) | ||||
cond1 = np.argmax(self._def_preds, axis=1) == self._true_labels | cond1 = np.argmax(self._def_preds, axis=1) == self._true_labels | ||||
@@ -147,9 +138,6 @@ class DefenseEvaluate: | |||||
more successful the defense. | more successful the defense. | ||||
- If return value == -1, idxes == 0. | - If return value == -1, idxes == 0. | ||||
Examples: | |||||
>>> def_eval.cos() | |||||
""" | """ | ||||
idxes = np.arange(self._num_samples) | idxes = np.arange(self._num_samples) | ||||
cond1 = np.argmax(self._def_preds, axis=1) == self._true_labels | cond1 = np.argmax(self._def_preds, axis=1) == self._true_labels | ||||
@@ -39,7 +39,7 @@ class ClipMechanismsFactory: | |||||
Wrapper of clip noise generating mechanisms. It supports Adaptive Clipping with | Wrapper of clip noise generating mechanisms. It supports Adaptive Clipping with | ||||
Gaussian Random Noise for now. | Gaussian Random Noise for now. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_. | |||||
""" | """ | ||||
@@ -49,7 +49,7 @@ class ClipMechanismsFactory: | |||||
@staticmethod | @staticmethod | ||||
def create(mech_name, decay_policy='Linear', learning_rate=0.001, | def create(mech_name, decay_policy='Linear', learning_rate=0.001, | ||||
target_unclipped_quantile=0.9, fraction_stddev=0.01, seed=0): | target_unclipped_quantile=0.9, fraction_stddev=0.01, seed=0): | ||||
""" | |||||
r""" | |||||
Args: | Args: | ||||
mech_name(str): Clip noise generated strategy, support 'Gaussian' now. | mech_name(str): Clip noise generated strategy, support 'Gaussian' now. | ||||
decay_policy(str): Decay policy of adaptive clipping, decay_policy must | decay_policy(str): Decay policy of adaptive clipping, decay_policy must | ||||
@@ -57,7 +57,7 @@ class ClipMechanismsFactory: | |||||
learning_rate(float): Learning rate of update norm clip. Default: 0.001. | learning_rate(float): Learning rate of update norm clip. Default: 0.001. | ||||
target_unclipped_quantile(float): Target quantile of norm clip. Default: 0.9. | target_unclipped_quantile(float): Target quantile of norm clip. Default: 0.9. | ||||
fraction_stddev(float): The stddev of Gaussian normal which used in | fraction_stddev(float): The stddev of Gaussian normal which used in | ||||
empirical_fraction, the formula is :math:`empirical_fraction + N(0, fraction_stddev)`. | |||||
empirical_fraction, the formula is :math:`empirical\_fraction + N(0, fraction\_stddev)`. | |||||
Default: 0.01. | Default: 0.01. | ||||
seed(int): Original random seed, if seed=0 random normal will use secure | seed(int): Original random seed, if seed=0 random normal will use secure | ||||
random number. IF seed!=0 random normal will generate values using | random number. IF seed!=0 random normal will generate values using | ||||
@@ -100,7 +100,7 @@ class NoiseMechanismsFactory: | |||||
Wrapper of noise generating mechanisms. It supports Gaussian Random Noise and | Wrapper of noise generating mechanisms. It supports Gaussian Random Noise and | ||||
Adaptive Gaussian Random Noise for now. | Adaptive Gaussian Random Noise for now. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_. | |||||
""" | """ | ||||
def __init__(self): | def __init__(self): | ||||
@@ -168,9 +168,9 @@ class _Mechanisms(Cell): | |||||
class NoiseGaussianRandom(_Mechanisms): | class NoiseGaussianRandom(_Mechanisms): | ||||
""" | |||||
r""" | |||||
Generate noise in Gaussian Distribution with :math:`mean=0` and | Generate noise in Gaussian Distribution with :math:`mean=0` and | ||||
:math:`standard deviation = norm_bound * initial_noise_multiplier`. | |||||
:math:`standard\_deviation = norm\_bound * initial\_noise\_multiplier`. | |||||
Args: | Args: | ||||
norm_bound(float): Clipping bound for the l2 norm of the gradients. | norm_bound(float): Clipping bound for the l2 norm of the gradients. | ||||
@@ -347,11 +347,11 @@ class _MechanismsParamsUpdater(Cell): | |||||
class AdaClippingWithGaussianRandom(Cell): | class AdaClippingWithGaussianRandom(Cell): | ||||
""" | |||||
Adaptive clipping. If `decay_policy` is 'Linear', the update formula :math:`norm_bound = norm_bound - | |||||
learning_rate*(beta - target_unclipped_quantile)`. | |||||
If `decay_policy` is 'Geometric', the update formula is :math:`norm_bound = | |||||
norm_bound*exp(-learning_rate*(empirical_fraction - target_unclipped_quantile))`. | |||||
r""" | |||||
Adaptive clipping. If `decay_policy` is 'Linear', the update formula :math:`norm\_bound = norm\_bound - | |||||
learning\_rate*(beta - target\_unclipped\_quantile)`. | |||||
If `decay_policy` is 'Geometric', the update formula is :math:`norm\_bound = | |||||
norm\_bound*exp(-learning\_rate*(empirical\_fraction - target\_unclipped\_quantile))`. | |||||
where beta is the empirical fraction of samples with the value at most | where beta is the empirical fraction of samples with the value at most | ||||
`target_unclipped_quantile`. | `target_unclipped_quantile`. | ||||
@@ -28,7 +28,7 @@ TAG = 'DP monitor' | |||||
class PrivacyMonitorFactory: | class PrivacyMonitorFactory: | ||||
""" | """ | ||||
Factory class of DP training's privacy monitor. | Factory class of DP training's privacy monitor. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_. | |||||
""" | """ | ||||
@@ -77,7 +77,7 @@ class RDPMonitor(Callback): | |||||
.. math:: | .. math:: | ||||
(ε'+\frac{log(1/δ)}{α-1}, δ) | (ε'+\frac{log(1/δ)}{α-1}, δ) | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_. | |||||
Reference: `Rényi Differential Privacy of the Sampled Gaussian Mechanism | Reference: `Rényi Differential Privacy of the Sampled Gaussian Mechanism | ||||
<https://arxiv.org/abs/1908.10530>`_ | <https://arxiv.org/abs/1908.10530>`_ | ||||
@@ -370,7 +370,7 @@ class ZCDPMonitor(Callback): | |||||
noise mechanisms(such as NoiseAdaGaussianRandom and NoiseGaussianRandom). | noise mechanisms(such as NoiseAdaGaussianRandom and NoiseGaussianRandom). | ||||
The matching noise mechanism of ZCDP will be developed in the future. | The matching noise mechanism of ZCDP will be developed in the future. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_. | |||||
Reference: `Concentrated Differentially Private Gradient Descent with | Reference: `Concentrated Differentially Private Gradient Descent with | ||||
Adaptive per-Iteration Privacy Budget <https://arxiv.org/abs/1808.09501>`_ | Adaptive per-Iteration Privacy Budget <https://arxiv.org/abs/1808.09501>`_ | ||||
@@ -70,7 +70,7 @@ class DPModel(Model): | |||||
DPModel is used for constructing a model for differential privacy training. | DPModel is used for constructing a model for differential privacy training. | ||||
This class is overload mindspore.train.model.Model. | This class is overload mindspore.train.model.Model. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_differential_privacy.html#%E5%B7%AE%E5%88%86%E9%9A%90%E7%A7%81>`_. | |||||
Args: | Args: | ||||
micro_batches (int): The number of small batches split from an original | micro_batches (int): The number of small batches split from an original | ||||
@@ -98,7 +98,7 @@ class MembershipInference: | |||||
for inferring user's privacy data. It requires loss or logits results of the training samples. | for inferring user's privacy data. It requires loss or logits results of the training samples. | ||||
(Privacy refers to some sensitive attributes of a single user). | (Privacy refers to some sensitive attributes of a single user). | ||||
For details, please refer to the `Tutorial <https://mindspore.cn/mindarmour/docs/en/master/test_model_security_membership_inference.html>`_ | |||||
For details, please refer to the `Tutorial <https://mindspore.cn/mindarmour/docs/en/master/test_model_security_membership_inference.html>`_. | |||||
References: `Reza Shokri, Marco Stronati, Congzheng Song, Vitaly Shmatikov. | References: `Reza Shokri, Marco Stronati, Congzheng Song, Vitaly Shmatikov. | ||||
Membership Inference Attacks against Machine Learning Models. 2017. | Membership Inference Attacks against Machine Learning Models. 2017. | ||||
@@ -27,7 +27,7 @@ TAG = 'suppress masker' | |||||
class SuppressMasker(Callback): | class SuppressMasker(Callback): | ||||
""" | """ | ||||
Periodicity check suppress privacy function status and toggle suppress operation. | Periodicity check suppress privacy function status and toggle suppress operation. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html#%E5%BC%95%E5%85%A5%E6%8A%91%E5%88%B6%E9%9A%90%E7%A7%81%E8%AE%AD%E7%BB%83>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html#%E5%BC%95%E5%85%A5%E6%8A%91%E5%88%B6%E9%9A%90%E7%A7%81%E8%AE%AD%E7%BB%83>`_. | |||||
Args: | Args: | ||||
model (SuppressModel): SuppressModel instance. | model (SuppressModel): SuppressModel instance. | ||||
@@ -32,7 +32,11 @@ TAG = 'Suppression training.' | |||||
class SuppressPrivacyFactory: | class SuppressPrivacyFactory: | ||||
""" Factory class of SuppressCtrl mechanisms""" | |||||
""" | |||||
Factory class of SuppressCtrl mechanisms. | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html#%E5%BC%95%E5%85%A5%E6%8A%91%E5%88%B6%E9%9A%90%E7%A7%81%E8%AE%AD%E7%BB%83>`_. | |||||
""" | |||||
def __init__(self): | def __init__(self): | ||||
pass | pass | ||||
@@ -41,8 +45,6 @@ class SuppressPrivacyFactory: | |||||
def create(networks, mask_layers, policy="local_train", end_epoch=10, batch_num=20, start_epoch=3, | def create(networks, mask_layers, policy="local_train", end_epoch=10, batch_num=20, start_epoch=3, | ||||
mask_times=1000, lr=0.05, sparse_end=0.90, sparse_start=0.0): | mask_times=1000, lr=0.05, sparse_end=0.90, sparse_start=0.0): | ||||
""" | """ | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html#%E5%BC%95%E5%85%A5%E6%8A%91%E5%88%B6%E9%9A%90%E7%A7%81%E8%AE%AD%E7%BB%83>`_ | |||||
Args: | Args: | ||||
networks (Cell): The training network. | networks (Cell): The training network. | ||||
This networks parameter should be same as 'network' parameter of SuppressModel(). | This networks parameter should be same as 'network' parameter of SuppressModel(). | ||||
@@ -116,7 +118,7 @@ class SuppressCtrl(Cell): | |||||
finding the parameters that should be suppressed, and suppress these | finding the parameters that should be suppressed, and suppress these | ||||
parameters permanently. | parameters permanently. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html#%E5%BC%95%E5%85%A5%E6%8A%91%E5%88%B6%E9%9A%90%E7%A7%81%E8%AE%AD%E7%BB%83>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html#%E5%BC%95%E5%85%A5%E6%8A%91%E5%88%B6%E9%9A%90%E7%A7%81%E8%AE%AD%E7%BB%83>`_. | |||||
Args: | Args: | ||||
networks (Cell): The training network. | networks (Cell): The training network. | ||||
@@ -59,7 +59,7 @@ class SuppressModel(Model): | |||||
Complete model train function. The suppress privacy function is embedded into the overload | Complete model train function. The suppress privacy function is embedded into the overload | ||||
mindspore.train.model.Model. | mindspore.train.model.Model. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/protect_user_privacy_with_suppress_privacy.html>`_. | |||||
Args: | Args: | ||||
network (Cell): The training network. | network (Cell): The training network. | ||||
@@ -89,7 +89,7 @@ class OodDetectorFeatureCluster(OodDetector): | |||||
the testing data features and the clustering centers determines whether an image is an out-of-distribution(OOD) | the testing data features and the clustering centers determines whether an image is an out-of-distribution(OOD) | ||||
image or not. | image or not. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/concept_drift_images.html>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/concept_drift_images.html>`_. | |||||
Args: | Args: | ||||
model (Model):The training model. | model (Model):The training model. | ||||
@@ -23,7 +23,7 @@ from mindarmour.utils._check_param import check_param_type, check_param_in_range | |||||
class ConceptDriftCheckTimeSeries: | class ConceptDriftCheckTimeSeries: | ||||
r""" | r""" | ||||
ConceptDriftCheckTimeSeries is used for example series distribution change detection. | ConceptDriftCheckTimeSeries is used for example series distribution change detection. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/concept_drift_time_series.html>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/concept_drift_time_series.html>`_. | |||||
Args: | Args: | ||||
window_size(int): Size of a concept window, no less than 10. If given the input data, | window_size(int): Size of a concept window, no less than 10. If given the input data, | ||||
@@ -31,7 +31,7 @@ class FaultInjector: | |||||
Fault injection module simulates various fault scenarios for deep neural networks and evaluates | Fault injection module simulates various fault scenarios for deep neural networks and evaluates | ||||
performance and reliability of the model. | performance and reliability of the model. | ||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/fault_injection.html>`_ | |||||
For details, please check `Tutorial <https://mindspore.cn/mindarmour/docs/zh-CN/master/fault_injection.html>`_. | |||||
Args: | Args: | ||||
model (Model): The model need to be evaluated. | model (Model): The model need to be evaluated. | ||||
@@ -196,7 +196,7 @@ class FaultInjector: | |||||
def kick_off(self, ds_data, ds_label, iter_times=100): | def kick_off(self, ds_data, ds_label, iter_times=100): | ||||
""" | """ | ||||
Startup and return final results. | |||||
Startup and return final results after Fault Injection. | |||||
Args: | Args: | ||||
ds_data(np.ndarray): Input data for testing. The evaluation is based on this data. | ds_data(np.ndarray): Input data for testing. The evaluation is based on this data. | ||||
@@ -241,9 +241,10 @@ class FaultInjector: | |||||
def metrics(self): | def metrics(self): | ||||
""" | """ | ||||
metrics of final result. | |||||
Metrics of final result. | |||||
Returns: | Returns: | ||||
list, the summary of result. | |||||
- list, the summary of result. | |||||
""" | """ | ||||
result_summary = [] | result_summary = [] | ||||
single_layer_acc = [] | single_layer_acc = [] | ||||