diff --git a/mindarmour/diff_privacy/evaluation/__init__.py b/mindarmour/diff_privacy/evaluation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mindarmour/diff_privacy/evaluation/attacker.py b/mindarmour/diff_privacy/evaluation/attacker.py index 5b10d22..1e70eef 100644 --- a/mindarmour/diff_privacy/evaluation/attacker.py +++ b/mindarmour/diff_privacy/evaluation/attacker.py @@ -121,10 +121,10 @@ def get_attack_model(features, labels, config): method = str.lower(config["method"]) if method == "knn": return _attack_knn(features, labels, config["params"]) - if method == "LR": + if method in ["lr", "logitic regression"]: return _attack_lr(features, labels, config["params"]) - if method == "MLP": + if method == "mlp": return _attack_mlpc(features, labels, config["params"]) - if method == "RF": + if method in ["rf", "random forest"]: return _attack_rf(features, labels, config["params"]) raise ValueError("Method {} is not support.".format(config["method"])) diff --git a/requirements.txt b/requirements.txt index 96b4d47..de1c175 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ Pillow >= 2.0.0 pytest >= 4.3.1 wheel >= 0.32.0 setuptools >= 40.8.0 +scikit-learn >= 0.21.2 diff --git a/setup.py b/setup.py index b622c3e..50e570d 100644 --- a/setup.py +++ b/setup.py @@ -105,7 +105,8 @@ setup( 'scipy >= 1.3.3', 'numpy >= 1.17.0', 'matplotlib >= 3.2.1', - 'Pillow >= 2.0.0' + 'Pillow >= 2.0.0', + 'scikit-learn >= 0.21.2' ], classifiers=[ 'License :: OSI Approved :: Apache Software License' diff --git a/tests/ut/python/diff_privacy/test_attacker.py b/tests/ut/python/diff_privacy/test_attacker.py index a03b2f8..9046e2b 100644 --- a/tests/ut/python/diff_privacy/test_attacker.py +++ b/tests/ut/python/diff_privacy/test_attacker.py @@ -18,16 +18,12 @@ import pytest import numpy as np -from sklearn.neighbors import KNeighborsClassifier as knn -from sklearn.linear_model import LogisticRegression -from sklearn.neural_network import MLPClassifier -from sklearn.ensemble import RandomForestClassifier - from mindarmour.diff_privacy.evaluation.attacker import get_attack_model @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_get_knn_model(): @@ -36,17 +32,17 @@ def test_get_knn_model(): config_knn = { "method": "KNN", "params": { - "n_neighbors": [3, 5, 7], + "n_neighbors": [3], } } knn_attacker = get_attack_model(features, labels, config_knn) - assert isinstance(knn_attacker, knn) pred = knn_attacker.predict(features) assert pred is not None @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_get_lr_model(): @@ -59,13 +55,13 @@ def test_get_lr_model(): } } lr_attacker = get_attack_model(features, labels, config_lr) - assert isinstance(lr_attacker, LogisticRegression) pred = lr_attacker.predict(features) assert pred is not None @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_get_mlp_model(): @@ -80,13 +76,13 @@ def test_get_mlp_model(): } } mlpc_attacker = get_attack_model(features, labels, config_mlpc) - assert isinstance(mlpc_attacker, MLPClassifier) pred = mlpc_attacker.predict(features) assert pred is not None @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_get_rf_model(): @@ -103,6 +99,5 @@ def test_get_rf_model(): } } rf_attacker = get_attack_model(features, labels, config_rf) - assert isinstance(rf_attacker, RandomForestClassifier) pred = rf_attacker.predict(features) assert pred is not None diff --git a/tests/ut/python/diff_privacy/test_mechanisms.py b/tests/ut/python/diff_privacy/test_mechanisms.py index d014a3a..2e2f7f7 100644 --- a/tests/ut/python/diff_privacy/test_mechanisms.py +++ b/tests/ut/python/diff_privacy/test_mechanisms.py @@ -27,6 +27,7 @@ from mindarmour.diff_privacy import ClipMechanismsFactory @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_graph_factory(): @@ -53,6 +54,7 @@ def test_graph_factory(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_pynative_factory(): @@ -79,6 +81,7 @@ def test_pynative_factory(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_pynative_gaussian(): @@ -105,6 +108,7 @@ def test_pynative_gaussian(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_graph_ada_gaussian(): @@ -125,6 +129,7 @@ def test_graph_ada_gaussian(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_pynative_ada_gaussian(): @@ -145,6 +150,7 @@ def test_pynative_ada_gaussian(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_graph_exponential(): @@ -166,6 +172,7 @@ def test_graph_exponential(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_pynative_exponential(): @@ -187,6 +194,7 @@ def test_pynative_exponential(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_ada_clip_gaussian_random_pynative(): @@ -217,6 +225,7 @@ def test_ada_clip_gaussian_random_pynative(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_ada_clip_gaussian_random_graph(): @@ -247,6 +256,7 @@ def test_ada_clip_gaussian_random_graph(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_pynative_clip_mech_factory(): @@ -269,6 +279,7 @@ def test_pynative_clip_mech_factory(): @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard @pytest.mark.component_mindarmour def test_graph_clip_mech_factory():