You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_radar_metric.py 2.0 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. Radar map test.
  16. """
  17. import pytest
  18. from mindarmour.evaluations.visual_metrics import RadarMetric
  19. @pytest.mark.level0
  20. @pytest.mark.platform_arm_ascend_training
  21. @pytest.mark.platform_x86_ascend_training
  22. @pytest.mark.env_card
  23. @pytest.mark.component_mindarmour
  24. def test_radar_metric():
  25. # prepare data
  26. metrics_name = ['MR', 'ACAC', 'ASS', 'NTE', 'RGB']
  27. def_metrics = [0.9, 0.85, 0.6, 0.7, 0.8]
  28. raw_metrics = [0.5, 0.3, 0.55, 0.65, 0.7]
  29. metrics_data = [def_metrics, raw_metrics]
  30. metrics_labels = ['before', 'after']
  31. # create obj
  32. rm = RadarMetric(metrics_name, metrics_data, metrics_labels, title='',
  33. scale='sparse')
  34. @pytest.mark.level0
  35. @pytest.mark.platform_arm_ascend_training
  36. @pytest.mark.platform_x86_ascend_training
  37. @pytest.mark.env_card
  38. @pytest.mark.component_mindarmour
  39. def test_value_error():
  40. # prepare data
  41. metrics_name = ['MR', 'ACAC', 'ASS', 'NTE', 'RGB']
  42. def_metrics = [0.9, 0.85, 0.6, 0.7, 0.8]
  43. raw_metrics = [0.5, 0.3, 0.55, 0.65, 0.7]
  44. metrics_data = [def_metrics, raw_metrics]
  45. metrics_labels = ['before', 'after']
  46. with pytest.raises(ValueError):
  47. assert RadarMetric(metrics_name, metrics_data, metrics_labels,
  48. title='', scale='bad_s')
  49. with pytest.raises(ValueError):
  50. assert RadarMetric(['MR', 'ACAC', 'ASS'], metrics_data, metrics_labels,
  51. title='', scale='bad_s')

MindArmour关注AI的安全和隐私问题。致力于增强模型的安全可信、保护用户的数据隐私。主要包含3个模块:对抗样本鲁棒性模块、Fuzz Testing模块、隐私保护与评估模块。 对抗样本鲁棒性模块 对抗样本鲁棒性模块用于评估模型对于对抗样本的鲁棒性,并提供模型增强方法用于增强模型抗对抗样本攻击的能力,提升模型鲁棒性。对抗样本鲁棒性模块包含了4个子模块:对抗样本的生成、对抗样本的检测、模型防御、攻防评估。