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_image_transform.py 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. Image transform test.
  16. """
  17. import numpy as np
  18. import pytest
  19. from mindarmour.utils.logger import LogUtil
  20. from mindarmour.fuzz_testing.image_transform import Contrast, Brightness, \
  21. Blur, Noise, Translate, Scale, Shear, Rotate
  22. LOGGER = LogUtil.get_instance()
  23. TAG = 'Image transform test'
  24. LOGGER.set_level('INFO')
  25. @pytest.mark.level0
  26. @pytest.mark.platform_x86_cpu
  27. @pytest.mark.env_onecard
  28. @pytest.mark.component_mindarmour
  29. def test_contrast():
  30. image = (np.random.rand(32, 32)).astype(np.float32)
  31. trans = Contrast()
  32. trans.set_params(auto_param=True)
  33. _ = trans.transform(image)
  34. @pytest.mark.level0
  35. @pytest.mark.platform_x86_cpu
  36. @pytest.mark.env_onecard
  37. @pytest.mark.component_mindarmour
  38. def test_brightness():
  39. image = (np.random.rand(32, 32)).astype(np.float32)
  40. trans = Brightness()
  41. trans.set_params(auto_param=True)
  42. _ = trans.transform(image)
  43. @pytest.mark.level0
  44. @pytest.mark.platform_x86_cpu
  45. @pytest.mark.platform_x86_ascend_training
  46. @pytest.mark.platform_arm_ascend_training
  47. @pytest.mark.env_onecard
  48. @pytest.mark.component_mindarmour
  49. def test_blur():
  50. image = (np.random.rand(32, 32)).astype(np.float32)
  51. trans = Blur()
  52. trans.set_params(auto_param=True)
  53. _ = trans.transform(image)
  54. @pytest.mark.level0
  55. @pytest.mark.platform_x86_cpu
  56. @pytest.mark.platform_x86_ascend_training
  57. @pytest.mark.platform_arm_ascend_training
  58. @pytest.mark.env_onecard
  59. @pytest.mark.component_mindarmour
  60. def test_noise():
  61. image = (np.random.rand(32, 32)).astype(np.float32)
  62. trans = Noise()
  63. trans.set_params(auto_param=True)
  64. _ = trans.transform(image)
  65. @pytest.mark.level0
  66. @pytest.mark.platform_x86_cpu
  67. @pytest.mark.platform_x86_ascend_training
  68. @pytest.mark.platform_arm_ascend_training
  69. @pytest.mark.env_onecard
  70. @pytest.mark.component_mindarmour
  71. def test_translate():
  72. image = (np.random.rand(32, 32)).astype(np.float32)
  73. trans = Translate()
  74. trans.set_params(auto_param=True)
  75. _ = trans.transform(image)
  76. @pytest.mark.level0
  77. @pytest.mark.platform_x86_cpu
  78. @pytest.mark.platform_x86_ascend_training
  79. @pytest.mark.platform_arm_ascend_training
  80. @pytest.mark.env_onecard
  81. @pytest.mark.component_mindarmour
  82. def test_shear():
  83. image = (np.random.rand(32, 32)).astype(np.float32)
  84. trans = Shear()
  85. trans.set_params(auto_param=True)
  86. _ = trans.transform(image)
  87. @pytest.mark.level0
  88. @pytest.mark.platform_x86_cpu
  89. @pytest.mark.platform_x86_ascend_training
  90. @pytest.mark.platform_arm_ascend_training
  91. @pytest.mark.env_onecard
  92. @pytest.mark.component_mindarmour
  93. def test_scale():
  94. image = (np.random.rand(32, 32)).astype(np.float32)
  95. trans = Scale()
  96. trans.set_params(auto_param=True)
  97. _ = trans.transform(image)
  98. @pytest.mark.level0
  99. @pytest.mark.platform_x86_cpu
  100. @pytest.mark.platform_x86_ascend_training
  101. @pytest.mark.platform_arm_ascend_training
  102. @pytest.mark.env_onecard
  103. @pytest.mark.component_mindarmour
  104. def test_rotate():
  105. image = (np.random.rand(32, 32)).astype(np.float32)
  106. trans = Rotate()
  107. trans.set_params(auto_param=True)
  108. _ = trans.transform(image)

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