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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.utils.image_transform import Contrast, Brightness, Blur, Noise, \
  21. 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)*255).astype(np.float32)
  31. mode = 'L'
  32. trans = Contrast(image, mode)
  33. trans.random_param()
  34. trans_image = trans.transform()
  35. @pytest.mark.level0
  36. @pytest.mark.platform_x86_cpu
  37. @pytest.mark.env_onecard
  38. @pytest.mark.component_mindarmour
  39. def test_brightness():
  40. image = (np.random.rand(32, 32)*255).astype(np.float32)
  41. mode = 'L'
  42. trans = Brightness(image, mode)
  43. trans.random_param()
  44. trans_image = trans.transform()
  45. @pytest.mark.level0
  46. @pytest.mark.platform_x86_cpu
  47. @pytest.mark.platform_x86_ascend_training
  48. @pytest.mark.platform_arm_ascend_training
  49. @pytest.mark.env_onecard
  50. @pytest.mark.component_mindarmour
  51. def test_blur():
  52. image = (np.random.rand(32, 32)*255).astype(np.float32)
  53. mode = 'L'
  54. trans = Blur(image, mode)
  55. trans.random_param()
  56. trans_image = trans.transform()
  57. @pytest.mark.level0
  58. @pytest.mark.platform_x86_cpu
  59. @pytest.mark.platform_x86_ascend_training
  60. @pytest.mark.platform_arm_ascend_training
  61. @pytest.mark.env_onecard
  62. @pytest.mark.component_mindarmour
  63. def test_noise():
  64. image = (np.random.rand(32, 32)*255).astype(np.float32)
  65. mode = 'L'
  66. trans = Noise(image, mode)
  67. trans.random_param()
  68. trans_image = trans.transform()
  69. @pytest.mark.level0
  70. @pytest.mark.platform_x86_cpu
  71. @pytest.mark.platform_x86_ascend_training
  72. @pytest.mark.platform_arm_ascend_training
  73. @pytest.mark.env_onecard
  74. @pytest.mark.component_mindarmour
  75. def test_translate():
  76. image = (np.random.rand(32, 32)*255).astype(np.float32)
  77. mode = 'L'
  78. trans = Translate(image, mode)
  79. trans.random_param()
  80. trans_image = trans.transform()
  81. @pytest.mark.level0
  82. @pytest.mark.platform_x86_cpu
  83. @pytest.mark.platform_x86_ascend_training
  84. @pytest.mark.platform_arm_ascend_training
  85. @pytest.mark.env_onecard
  86. @pytest.mark.component_mindarmour
  87. def test_shear():
  88. image = (np.random.rand(32, 32)*255).astype(np.float32)
  89. mode = 'L'
  90. trans = Shear(image, mode)
  91. trans.random_param()
  92. trans_image = trans.transform()
  93. @pytest.mark.level0
  94. @pytest.mark.platform_x86_cpu
  95. @pytest.mark.platform_x86_ascend_training
  96. @pytest.mark.platform_arm_ascend_training
  97. @pytest.mark.env_onecard
  98. @pytest.mark.component_mindarmour
  99. def test_scale():
  100. image = (np.random.rand(32, 32)*255).astype(np.float32)
  101. mode = 'L'
  102. trans = Scale(image, mode)
  103. trans.random_param()
  104. trans_image = trans.transform()
  105. @pytest.mark.level0
  106. @pytest.mark.platform_x86_cpu
  107. @pytest.mark.platform_x86_ascend_training
  108. @pytest.mark.platform_arm_ascend_training
  109. @pytest.mark.env_onecard
  110. @pytest.mark.component_mindarmour
  111. def test_rotate():
  112. image = (np.random.rand(32, 32)*255).astype(np.float32)
  113. mode = 'L'
  114. trans = Rotate(image, mode)
  115. trans.random_param()
  116. trans_image = trans.transform()

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