提交 1e0bc592 编写于 作者: P pkuliuliu

adjust the project structure according to diff features

上级 432d302a
......@@ -28,7 +28,7 @@ import numpy as np
from mindspore.train import Model
from mindspore.train.serialization import load_param_into_net, load_checkpoint
import mindspore.nn as nn
from mindarmour.diff_privacy.evaluation.membership_inference import MembershipInference
from mindarmour.privacy.evaluation import MembershipInference
from mindarmour.utils import LogUtil
logging = LogUtil.get_instance()
logging.set_level(20)
......
......@@ -29,10 +29,10 @@ import mindspore.dataset.transforms.c_transforms as C
from mindspore.dataset.transforms.vision import Inter
import mindspore.common.dtype as mstype
from mindarmour.diff_privacy import DPModel
from mindarmour.diff_privacy import PrivacyMonitorFactory
from mindarmour.diff_privacy import NoiseMechanismsFactory
from mindarmour.diff_privacy import ClipMechanismsFactory
from mindarmour.privacy.diff_privacy import DPModel
from mindarmour.privacy.diff_privacy import PrivacyMonitorFactory
from mindarmour.privacy.diff_privacy import NoiseMechanismsFactory
from mindarmour.privacy.diff_privacy import ClipMechanismsFactory
from mindarmour.utils.logger import LogUtil
from lenet5_net import LeNet5
from lenet5_config import mnist_cfg as cfg
......
......@@ -29,9 +29,9 @@ import mindspore.dataset.transforms.c_transforms as C
from mindspore.dataset.transforms.vision import Inter
import mindspore.common.dtype as mstype
from mindarmour.diff_privacy import DPModel
from mindarmour.diff_privacy import PrivacyMonitorFactory
from mindarmour.diff_privacy import NoiseMechanismsFactory
from mindarmour.privacy.diff_privacy import DPModel
from mindarmour.privacy.diff_privacy import PrivacyMonitorFactory
from mindarmour.privacy.diff_privacy import NoiseMechanismsFactory
from mindarmour.utils.logger import LogUtil
from lenet5_net import LeNet5
from dp_ada_gaussian_config import mnist_cfg as cfg
......
......@@ -29,9 +29,9 @@ import mindspore.dataset.transforms.c_transforms as C
from mindspore.dataset.transforms.vision import Inter
import mindspore.common.dtype as mstype
from mindarmour.diff_privacy import DPModel
from mindarmour.diff_privacy import PrivacyMonitorFactory
from mindarmour.diff_privacy import NoiseMechanismsFactory
from mindarmour.privacy.diff_privacy import DPModel
from mindarmour.privacy.diff_privacy import PrivacyMonitorFactory
from mindarmour.privacy.diff_privacy import NoiseMechanismsFactory
from mindarmour.utils.logger import LogUtil
from lenet5_net import LeNet5
from dp_ada_sgd_graph_config import mnist_cfg as cfg
......
......@@ -29,10 +29,10 @@ import mindspore.dataset.transforms.c_transforms as C
from mindspore.dataset.transforms.vision import Inter
import mindspore.common.dtype as mstype
from mindarmour.diff_privacy import DPModel
from mindarmour.diff_privacy import PrivacyMonitorFactory
from mindarmour.diff_privacy import DPOptimizerClassFactory
from mindarmour.diff_privacy import ClipMechanismsFactory
from mindarmour.privacy.diff_privacy import DPModel
from mindarmour.privacy.diff_privacy import PrivacyMonitorFactory
from mindarmour.privacy.diff_privacy import DPOptimizerClassFactory
from mindarmour.privacy.diff_privacy import ClipMechanismsFactory
from mindarmour.utils.logger import LogUtil
from lenet5_net import LeNet5
from lenet5_config import mnist_cfg as cfg
......
......@@ -20,8 +20,8 @@ from mindspore.nn import SoftmaxCrossEntropyWithLogits
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from lenet5_net import LeNet5
from mindarmour.attacks.gradient_method import FastGradientSignMethod
from mindarmour.fuzzing.model_coverage_metrics import ModelCoverageMetrics
from mindarmour.adv_robustness.attacks import FastGradientSignMethod
from mindarmour.fuzz_testing import ModelCoverageMetrics
from mindarmour.utils.logger import LogUtil
sys.path.append("..")
......
......@@ -19,8 +19,8 @@ from mindspore import context
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from lenet5_net import LeNet5
from mindarmour.fuzzing.fuzzing import Fuzzer
from mindarmour.fuzzing.model_coverage_metrics import ModelCoverageMetrics
from mindarmour.fuzz_testing import Fuzzer
from mindarmour.fuzz_testing import ModelCoverageMetrics
from mindarmour.utils.logger import LogUtil
sys.path.append("..")
......
......@@ -22,8 +22,8 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.carlini_wagner import CarliniWagnerL2Attack
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks import CarliniWagnerL2Attack
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -22,8 +22,8 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.deep_fool import DeepFool
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks.deep_fool import DeepFool
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -23,8 +23,8 @@ from mindspore.nn import SoftmaxCrossEntropyWithLogits
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.gradient_method import FastGradientSignMethod
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks import FastGradientSignMethod
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -21,9 +21,9 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.genetic_attack import GeneticAttack
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks import BlackModel
from mindarmour.adv_robustness.attacks.black.genetic_attack import GeneticAttack
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -19,8 +19,8 @@ from mindspore import context
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from lenet5_net import LeNet5
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.hop_skip_jump_attack import HopSkipJumpAttack
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import HopSkipJumpAttack
from mindarmour.utils.logger import LogUtil
sys.path.append("..")
......
......@@ -22,8 +22,8 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.jsma import JSMAAttack
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks import JSMAAttack
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -23,8 +23,8 @@ from mindspore.nn import SoftmaxCrossEntropyWithLogits
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.lbfgs import LBFGS
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks import LBFGS
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -23,9 +23,8 @@ from mindspore.nn import SoftmaxCrossEntropyWithLogits
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.iterative_gradient_method import \
MomentumDiverseInputIterativeMethod
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks import MomentumDiverseInputIterativeMethod
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -19,8 +19,8 @@ from mindspore import context
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from lenet5_net import LeNet5
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.natural_evolutionary_strategy import NES
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import NES
from mindarmour.utils.logger import LogUtil
sys.path.append("..")
......
......@@ -23,8 +23,8 @@ from mindspore.nn import SoftmaxCrossEntropyWithLogits
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.iterative_gradient_method import ProjectedGradientDescent
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour.adv_robustness.attacks import ProjectedGradientDescent
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -20,9 +20,9 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.pointwise_attack import PointWiseAttack
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import PointWiseAttack
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
sys.path.append("..")
......
......@@ -21,9 +21,9 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.pso_attack import PSOAttack
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks.black.pso_attack import PSOAttack
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
......
......@@ -20,9 +20,9 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.salt_and_pepper_attack import SaltAndPepperNoiseAttack
from mindarmour.evaluations.attack_evaluation import AttackEvaluate
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import SaltAndPepperNoiseAttack
from mindarmour.adv_robustness.evaluations import AttackEvaluate
from mindarmour.utils.logger import LogUtil
sys.path.append("..")
......
......@@ -23,8 +23,8 @@ from mindspore.nn import SoftmaxCrossEntropyWithLogits
from mindspore.train import Model
from mindspore.train.callback import LossMonitor
from mindarmour.attacks import FastGradientSignMethod
from mindarmour.defenses import NaturalAdversarialDefense
from mindarmour.adv_robustness.attacks import FastGradientSignMethod
from mindarmour.adv_robustness.defenses import NaturalAdversarialDefense
from mindarmour.utils.logger import LogUtil
from lenet5_net import LeNet5
......
......@@ -28,13 +28,13 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks import FastGradientSignMethod
from mindarmour.attacks import GeneticAttack
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.defenses import NaturalAdversarialDefense
from mindarmour.detectors.black.similarity_detector import SimilarityDetector
from mindarmour.evaluations import BlackDefenseEvaluate
from mindarmour.evaluations import DefenseEvaluate
from mindarmour.adv_robustness.attacks import FastGradientSignMethod
from mindarmour.adv_robustness.attacks import GeneticAttack
from mindarmour.adv_robustness.attacks import BlackModel
from mindarmour.adv_robustness.defenses import NaturalAdversarialDefense
from mindarmour.adv_robustness.detectors import SimilarityDetector
from mindarmour.adv_robustness.evaluations import BlackDefenseEvaluate
from mindarmour.adv_robustness.evaluations import DefenseEvaluate
from mindarmour.utils.logger import LogUtil
sys.path.append("..")
......
......@@ -23,9 +23,9 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from scipy.special import softmax
from lenet5_net import LeNet5
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.pso_attack import PSOAttack
from mindarmour.detectors.black.similarity_detector import SimilarityDetector
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks.black.pso_attack import PSOAttack
from mindarmour.adv_robustness.detectors import SimilarityDetector
from mindarmour.utils.logger import LogUtil
......
"""
MindArmour, a tool box of MindSpore to enhance model security and
trustworthiness against adversarial examples.
MindArmour, a tool box of MindSpore to enhance model trustworthiness and achieve
privacy-preserving machine learning.
"""
from .attacks import Attack
from .attacks.black.black_model import BlackModel
from .defenses.defense import Defense
from .detectors.detector import Detector
from .adv_robustness.attacks import Attack
from .adv_robustness.attacks.black.black_model import BlackModel
from .adv_robustness.defenses.defense import Defense
from .adv_robustness.detectors.detector import Detector
from .fuzz_testing.fuzzing import Fuzzer
from .privacy.diff_privacy import DPModel
from .privacy.evaluation.membership_inference import MembershipInference
__all__ = ['Attack',
'BlackModel',
'Detector',
'Defense']
'Defense',
'Fuzzer',
'DPModel',
'MembershipInference']
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Adversarial Robustness.
This module is a tool box to enhance model security and against adversarial
examples.
"""
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module includes classical black-box and white-box attack algorithms
in making adversarial examples.
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module is a submodule, which provides some black-box based adversarial method.
"""
......@@ -17,13 +17,12 @@ Genetic-Attack.
import numpy as np
from scipy.special import softmax
from mindarmour.attacks.attack import Attack
from mindarmour.utils.logger import LogUtil
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.utils._check_param import check_numpy_param, check_model, \
check_pair_numpy_param, check_param_type, check_value_positive, \
check_int_positive, check_param_multi_types
from ..attack import Attack
from .black_model import BlackModel
LOGGER = LogUtil.get_instance()
TAG = 'GeneticAttack'
......
......@@ -16,12 +16,13 @@ Hop-skip-jump attack.
"""
import numpy as np
from mindarmour.attacks.attack import Attack
from mindarmour.utils.logger import LogUtil
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.utils._check_param import check_pair_numpy_param, check_model, \
check_numpy_param, check_int_positive, check_value_positive, \
check_value_non_negative, check_param_type
from ..attack import Attack
from .black_model import BlackModel
LOGGER = LogUtil.get_instance()
TAG = 'HopSkipJumpAttack'
......
......@@ -18,12 +18,11 @@ import time
import numpy as np
from scipy.special import softmax
from mindarmour.attacks.attack import Attack
from mindarmour.utils.logger import LogUtil
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.utils._check_param import check_pair_numpy_param, check_model, \
check_numpy_param, check_int_positive, check_value_positive, check_param_type
from ..attack import Attack
from .black_model import BlackModel
LOGGER = LogUtil.get_instance()
TAG = 'NES'
......
......@@ -16,13 +16,12 @@ Pointwise-Attack.
"""
import numpy as np
from mindarmour.attacks.attack import Attack
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.salt_and_pepper_attack import \
SaltAndPepperNoiseAttack
from mindarmour.utils._check_param import check_model, check_pair_numpy_param, \
check_int_positive, check_param_type
from mindarmour.utils.logger import LogUtil
from ..attack import Attack
from .black_model import BlackModel
from .salt_and_pepper_attack import SaltAndPepperNoiseAttack
LOGGER = LogUtil.get_instance()
TAG = 'PointWiseAttack'
......
......@@ -16,13 +16,12 @@ PSO-Attack.
"""
import numpy as np
from mindarmour.attacks.attack import Attack
from mindarmour.utils.logger import LogUtil
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.utils._check_param import check_model, check_pair_numpy_param, \
check_numpy_param, check_value_positive, check_int_positive, \
check_param_type, check_equal_shape, check_param_multi_types
from ..attack import Attack
from .black_model import BlackModel
LOGGER = LogUtil.get_instance()
TAG = 'PSOAttack'
......
......@@ -18,12 +18,12 @@ import time
import numpy as np
from mindarmour.attacks.attack import Attack
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.utils._check_param import check_model, check_pair_numpy_param, \
check_param_type, check_int_positive, check_param_multi_types
from mindarmour.utils._check_param import normalize_value
from mindarmour.utils.logger import LogUtil
from ..attack import Attack
from .black_model import BlackModel
LOGGER = LogUtil.get_instance()
TAG = 'SaltAndPepperNoise-Attack'
......
......@@ -19,13 +19,12 @@ import numpy as np
from mindspore import Tensor
from mindspore.nn import Cell
from mindarmour.attacks.attack import Attack
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_numpy_param, check_model, \
check_pair_numpy_param, check_int_positive, check_param_type, \
check_param_multi_types, check_value_positive, check_equal_shape
from mindarmour.utils.util import GradWrap
from mindarmour.utils.util import jacobian_matrix
from mindarmour.utils.util import GradWrap, jacobian_matrix
from .attack import Attack
LOGGER = LogUtil.get_instance()
TAG = 'CW'
......
......@@ -19,13 +19,12 @@ import numpy as np
from mindspore import Tensor
from mindspore.nn import Cell
from mindarmour.attacks.attack import Attack
from mindarmour.utils.logger import LogUtil
from mindarmour.utils.util import GradWrap
from mindarmour.utils.util import jacobian_matrix
from mindarmour.utils.util import GradWrap, jacobian_matrix
from mindarmour.utils._check_param import check_pair_numpy_param, check_model, \
check_value_positive, check_int_positive, check_norm_level, \
check_param_multi_types, check_param_type
from .attack import Attack
LOGGER = LogUtil.get_instance()
TAG = 'DeepFool'
......
......@@ -19,16 +19,14 @@ from abc import abstractmethod
import numpy as np
from mindspore import Tensor
from mindspore.nn import Cell
from mindspore.nn import SoftmaxCrossEntropyWithLogits
from mindspore.nn import Cell, SoftmaxCrossEntropyWithLogits
from mindarmour.attacks.attack import Attack
from mindarmour.utils.util import WithLossCell
from mindarmour.utils.util import GradWrapWithLoss
from mindarmour.utils.util import WithLossCell, GradWrapWithLoss
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_pair_numpy_param, check_model, \
normalize_value, check_value_positive, check_param_multi_types, \
check_norm_level, check_param_type
from .attack import Attack
LOGGER = LogUtil.get_instance()
TAG = 'SingleGrad'
......
......@@ -17,18 +17,16 @@ from abc import abstractmethod
import numpy as np
from PIL import Image, ImageOps
from mindspore.nn import SoftmaxCrossEntropyWithLogits
from mindspore.nn import Cell, SoftmaxCrossEntropyWithLogits
from mindspore import Tensor
from mindspore.nn import Cell
from mindarmour.attacks.attack import Attack
from mindarmour.attacks.gradient_method import FastGradientSignMethod
from mindarmour.utils.logger import LogUtil
from mindarmour.utils.util import WithLossCell
from mindarmour.utils.util import GradWrapWithLoss
from mindarmour.utils.util import WithLossCell, GradWrapWithLoss
from mindarmour.utils._check_param import check_pair_numpy_param, \
normalize_value, check_model, check_value_positive, check_int_positive, \
check_param_type, check_norm_level, check_param_multi_types
from .attack import Attack
from .gradient_method import FastGradientSignMethod
LOGGER = LogUtil.get_instance()
TAG = 'IterGrad'
......
......@@ -19,14 +19,12 @@ import numpy as np
from mindspore import Tensor
from mindspore.nn import Cell
from mindarmour.attacks.attack import Attack
from mindarmour.utils.util import GradWrap
from mindarmour.utils.util import jacobian_matrix
from mindarmour.utils.util import GradWrap, jacobian_matrix
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_pair_numpy_param, check_model, \
check_param_type, check_int_positive, check_value_positive, \
check_value_non_negative
from .attack import Attack
LOGGER = LogUtil.get_instance()
TAG = 'JSMA'
......
......@@ -21,13 +21,12 @@ from mindspore import Tensor
from mindspore.nn import Cell
from mindspore.nn import SoftmaxCrossEntropyWithLogits
from mindarmour.attacks.attack import Attack
from mindarmour.utils.logger import LogUtil
from mindarmour.utils.util import WithLossCell
from mindarmour.utils.util import GradWrapWithLoss
from mindarmour.utils.util import WithLossCell, GradWrapWithLoss
from mindarmour.utils._check_param import check_pair_numpy_param, check_model, \
check_int_positive, check_value_positive, check_param_type, \
check_param_multi_types
from .attack import Attack
LOGGER = LogUtil.get_instance()
TAG = 'LBFGS'
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module includes classical defense algorithms in defencing adversarial
examples and enhancing model security and trustworthy.
......
......@@ -17,14 +17,13 @@ Adversarial Defense.
import numpy as np
from mindspore import Tensor
from mindspore.nn import Cell
from mindspore.nn.optim.momentum import Momentum
from mindspore.nn import SoftmaxCrossEntropyWithLogits
from mindspore.nn import Cell, SoftmaxCrossEntropyWithLogits
from mindspore.nn import WithLossCell, TrainOneStepCell
from mindspore.nn.optim.momentum import Momentum
from mindarmour.utils._check_param import check_pair_numpy_param, check_model, \
check_param_in_range, check_param_type, check_param_multi_types
from mindarmour.defenses.defense import Defense
from .defense import Defense
class AdversarialDefense(Defense):
......
......@@ -14,9 +14,8 @@
"""
Natural Adversarial Defense.
"""
from mindarmour.defenses.adversarial_defense import \
AdversarialDefenseWithAttacks
from mindarmour.attacks.gradient_method import FastGradientSignMethod
from ..attacks.gradient_method import FastGradientSignMethod
from .adversarial_defense import AdversarialDefenseWithAttacks
class NaturalAdversarialDefense(AdversarialDefenseWithAttacks):
......
......@@ -14,10 +14,8 @@
"""
Projected Adversarial Defense.
"""
from mindarmour.defenses.adversarial_defense import \
AdversarialDefenseWithAttacks
from mindarmour.attacks.iterative_gradient_method import \
ProjectedGradientDescent
from ..attacks.iterative_gradient_method import ProjectedGradientDescent
from .adversarial_defense import AdversarialDefenseWithAttacks
class ProjectedAdversarialDefense(AdversarialDefenseWithAttacks):
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module includes detector methods on distinguishing adversarial examples
from benign examples.
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
init black detector.
"""
......@@ -20,11 +20,11 @@ import numpy as np
from mindspore import Tensor
from mindspore import Model
from mindarmour.detectors.detector import Detector
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_model, check_numpy_param, \
check_int_positive, check_value_positive, check_param_type, \
check_param_in_range
from ..detector import Detector
LOGGER = LogUtil.get_instance()
TAG = 'SimilarityDetector'
......
......@@ -16,11 +16,10 @@ Ensemble Detector.
"""
import numpy as np
from mindarmour.detectors.detector import Detector
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_numpy_param, \
check_param_multi_types
from .detector import Detector
LOGGER = LogUtil.get_instance()
TAG = 'EnsembleDetector'
......
......@@ -21,11 +21,11 @@ from scipy.special import softmax
from mindspore import Tensor
from mindspore import Model
from mindarmour.detectors.detector import Detector
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_numpy_param, check_model, \
check_param_in_range, check_param_multi_types, check_int_positive, \
check_value_positive
from .detector import Detector
LOGGER = LogUtil.get_instance()
TAG = 'MagNet'
......
......@@ -21,12 +21,12 @@ import numpy as np
from mindspore import Model
from mindspore import Tensor
from mindarmour.detectors.detector import Detector
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_numpy_param, check_param_type, \
check_pair_numpy_param, check_model, check_int_positive, \
check_value_positive, check_value_non_negative, check_param_in_range, \
check_equal_shape
from .detector import Detector
LOGGER = LogUtil.get_instance()
TAG = 'RegionBasedDetector'
......
......@@ -20,11 +20,11 @@ from scipy import ndimage
from mindspore import Model
from mindspore import Tensor
from mindarmour.detectors.detector import Detector
from mindarmour.utils.logger import LogUtil
from mindarmour.utils._check_param import check_model, check_numpy_param, \
check_pair_numpy_param, check_int_positive, check_param_type, \
check_param_in_range, check_equal_shape, check_value_positive
from .detector import Detector
LOGGER = LogUtil.get_instance()
TAG = 'SpatialSmoothing'
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module includes various metrics to evaluate the result of attacks or
defenses.
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module provides a neuron coverage-gain based fuzz method to evaluate the
robustness of given model.
"""
from .fuzzing import Fuzzer
from .model_coverage_metrics import ModelCoverageMetrics
__all__ = ['Fuzzer',
'ModelCoverageMetrics']
......@@ -20,15 +20,15 @@ import numpy as np
from mindspore import Model
from mindspore import Tensor
from mindarmour.fuzzing.model_coverage_metrics import ModelCoverageMetrics
from mindarmour.utils._check_param import check_model, check_numpy_param, \
check_param_multi_types, check_norm_level, check_param_in_range, \
check_param_type, check_int_positive
from mindarmour.fuzzing.image_transform import Contrast, Brightness, Blur, \
Noise, Translate, Scale, Shear, Rotate
from mindarmour.attacks import FastGradientSignMethod, \
MomentumDiverseInputIterativeMethod, ProjectedGradientDescent
from mindarmour.utils.logger import LogUtil
from ..adv_robustness.attacks import FastGradientSignMethod, \
MomentumDiverseInputIterativeMethod, ProjectedGradientDescent
from .image_transform import Contrast, Brightness, Blur, \
Noise, Translate, Scale, Shear, Rotate
from .model_coverage_metrics import ModelCoverageMetrics
LOGGER = LogUtil.get_instance()
TAG = 'Fuzzer'
......@@ -95,7 +95,7 @@ class Fuzzer:
>>> {'method': 'FGSM', 'params': {'eps': 0.1, 'alpha': 0.1}}]
>>> train_images = np.random.rand(32, 1, 32, 32).astype(np.float32)
>>> model_fuzz_test = Fuzzer(model, train_images, 10, 1000)
>>> samples, labels, preds, strategies, report = model_fuzz_test.fuzzing(mutate_config, initial_seeds)
>>> samples, labels, preds, strategies, report = model_fuzz_test.fuzz_testing(mutate_config, initial_seeds)
"""
def __init__(self, target_model, train_dataset, neuron_num, segmented_num=1000):
......@@ -151,7 +151,7 @@ class Fuzzer:
'Rotate'. Thirdly, attack methods include: 'FGSM', 'PGD' and 'MDIIM'.
`mutate_config` must have method in the type of pixel value based
transform methods. The way of setting parameters for first and
second type methods can be seen in 'mindarmour/fuzzing/image_transform.py'.
second type methods can be seen in 'mindarmour/fuzz_testing/image_transform.py'.
For third type methods, you can refer to the corresponding class.
initial_seeds (list[list]): Initial seeds used to generate mutated
samples. The format of initial seeds is [[image_data, label],
......@@ -169,7 +169,7 @@ class Fuzzer:
Default: 20.
Returns:
- list, mutated samples in fuzzing.
- list, mutated samples in fuzz_testing.
- list, ground truth labels of mutated samples.
......@@ -376,11 +376,11 @@ class Fuzzer:
def _evaluate(self, fuzz_samples, gt_labels, fuzz_preds,
fuzz_strategies, metrics):
"""
Evaluate generated fuzzing samples in three dimention: accuracy,
Evaluate generated fuzz_testing samples in three dimention: accuracy,
attack success rate and neural coverage.
Args:
fuzz_samples (numpy.ndarray): Generated fuzzing samples according to seeds.
fuzz_samples (numpy.ndarray): Generated fuzz_testing samples according to seeds.
gt_labels (numpy.ndarray): Ground Truth of seeds.
fuzz_preds (numpy.ndarray): Predictions of generated fuzz samples.
fuzz_strategies (numpy.ndarray): Mutate strategies of fuzz samples.
......
"""
This module includes various metrics to fuzzing the test of DNN.
"""
from .fuzzing import Fuzzer
from .model_coverage_metrics import ModelCoverageMetrics
__all__ = ['Fuzzer',
'ModelCoverageMetrics']
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module provides various methods to protect the privacy of given model, and
also provides some methods to evaluate the risk of privacy leakage of given
model.
"""
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module provide Differential Privacy feature to protect user privacy.
This module provides Differential Privacy feature to protect user privacy.
"""
from .mechanisms.mechanisms import NoiseGaussianRandom
from .mechanisms.mechanisms import NoiseAdaGaussianRandom
......@@ -11,7 +24,6 @@ from .monitor.monitor import RDPMonitor
from .monitor.monitor import ZCDPMonitor
from .optimizer.optimizer import DPOptimizerClassFactory
from .train.model import DPModel
from .evaluation.membership_inference import MembershipInference
__all__ = ['NoiseGaussianRandom',
'NoiseAdaGaussianRandom',
......@@ -22,5 +34,4 @@ __all__ = ['NoiseGaussianRandom',
'RDPMonitor',
'ZCDPMonitor',
'DPOptimizerClassFactory',
'DPModel',
'MembershipInference']
'DPModel']
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
init mechanisms.
"""
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
init monitor.
"""
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
init optimizer.
"""
......@@ -22,9 +22,9 @@ from mindspore.ops import functional as F
from mindspore.common import dtype as mstype
from mindarmour.utils.logger import LogUtil
from mindarmour.diff_privacy import NoiseMechanismsFactory
from mindarmour.diff_privacy.mechanisms.mechanisms import _MechanismsParamsUpdater
from mindarmour.utils._check_param import check_int_positive
from ..mechanisms.mechanisms import NoiseMechanismsFactory
from ..mechanisms.mechanisms import _MechanismsParamsUpdater
LOGGER = LogUtil.get_instance()
TAG = 'DP optimizer'
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
init train.
"""
......@@ -48,10 +48,9 @@ from mindspore.nn import Cell
from mindspore import ParameterTuple
from mindarmour.utils.logger import LogUtil
from mindarmour.diff_privacy.mechanisms.mechanisms import \
_MechanismsParamsUpdater
from mindarmour.utils._check_param import check_value_positive, check_param_type
from mindarmour.utils._check_param import check_int_positive
from ..mechanisms.mechanisms import _MechanismsParamsUpdater
LOGGER = LogUtil.get_instance()
TAG = 'DP model'
......
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module provides some methods to evaluate the risk of privacy leakage of
given model.
"""
from .membership_inference import MembershipInference
__all__ = ['MembershipInference']
"""
Util methods of MindArmour."""
Util methods of MindArmour.
"""
from .logger import LogUtil
from .util import GradWrap
from .util import GradWrapWithLoss
......
......@@ -14,7 +14,7 @@
""" check parameters for MindArmour. """
import numpy as np
from mindarmour.utils.logger import LogUtil
from .logger import LogUtil
LOGGER = LogUtil.get_instance()
TAG = 'check parameters'
......
......@@ -17,7 +17,7 @@ from mindspore import Tensor
from mindspore.nn import Cell
from mindspore.ops.composite import GradOperation
from mindarmour.utils.logger import LogUtil
from .logger import LogUtil
LOGGER = LogUtil.get_instance()
TAG = 'util'
......
......@@ -29,7 +29,7 @@ from mindspore.common import dtype as mstype
from mindspore.ops import operations as P
from mindspore.ops import functional as F
from mindarmour.attacks.gradient_method import FastGradientSignMethod
from mindarmour.adv_robustness.attacks import FastGradientSignMethod
from resnet_cifar10 import resnet50_cifar10
......
......@@ -21,8 +21,8 @@ from mindspore import Tensor
from mindspore import context
from mindspore.nn import Cell
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.genetic_attack import GeneticAttack
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import GeneticAttack
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
......
......@@ -20,8 +20,8 @@ from mindspore import Tensor
from mindspore import context
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.hop_skip_jump_attack import HopSkipJumpAttack
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import HopSkipJumpAttack
from mindarmour.utils.logger import LogUtil
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),
......
......@@ -20,8 +20,8 @@ from mindspore import Tensor
from mindspore import context
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.natural_evolutionary_strategy import NES
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import NES
from mindarmour.utils.logger import LogUtil
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),
......
......@@ -23,8 +23,8 @@ from mindspore import Tensor
from mindspore import context
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.attacks.black.pointwise_attack import PointWiseAttack
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import PointWiseAttack
from mindarmour.utils.logger import LogUtil
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),
......
......@@ -22,8 +22,8 @@ import mindspore.nn as nn
from mindspore.nn import Cell
from mindspore import context
from mindarmour.attacks.black.pso_attack import PSOAttack
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour.adv_robustness.attacks import PSOAttack
from mindarmour import BlackModel
# for user
......
......@@ -22,9 +22,8 @@ from mindspore import Tensor
from mindspore.nn import Cell
from mindspore import context
from mindarmour.attacks.black.salt_and_pepper_attack import \
SaltAndPepperNoiseAttack
from mindarmour.attacks.black.black_model import BlackModel
from mindarmour import BlackModel
from mindarmour.adv_robustness.attacks import SaltAndPepperNoiseAttack
context.set_context(mode=context.GRAPH_MODE)
context.set_context(device_target="Ascend")
......
......@@ -21,7 +21,7 @@ import mindspore.ops.operations as P
from mindspore.nn import Cell
import mindspore.context as context
from mindarmour.attacks.gradient_method import FastGradientMethod
from mindarmour.adv_robustness.attacks import FastGradientMethod
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
......
......@@ -21,7 +21,7 @@ import mindspore.ops.operations as M
from mindspore.nn import Cell
from mindspore import context
from mindarmour.attacks.carlini_wagner import CarliniWagnerL2Attack
from mindarmour.adv_robustness.attacks import CarliniWagnerL2Attack
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
......
......@@ -17,12 +17,12 @@ DeepFool-Attack test.
import numpy as np
import pytest
import mindspore.ops.operations as M
import mindspore.ops.operations as P
from mindspore.nn import Cell
from mindspore import context
from mindspore import Tensor
from mindarmour.attacks.deep_fool import DeepFool
from mindarmour.adv_robustness.attacks import DeepFool
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
......@@ -41,7 +41,7 @@ class Net(Cell):
Introduce the layers used for network construction.
"""
super(Net, self).__init__()
self._softmax = M.Softmax()
self._softmax = P.Softmax()
def construct(self, inputs):
"""
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册