From 437e61c93f029b21a64ee1b27ae507ca67b4cc71 Mon Sep 17 00:00:00 2001 From: ZhidanLiu Date: Wed, 26 Aug 2020 11:37:53 +0800 Subject: [PATCH] keep the type of parameters in fuzzing consistent with that in the called methods --- mindarmour/fuzzing/fuzzing.py | 22 +++++++++++----------- mindarmour/fuzzing/image_transform.py | 12 ++++++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/mindarmour/fuzzing/fuzzing.py b/mindarmour/fuzzing/fuzzing.py index 3b8bcfc..2acc082 100644 --- a/mindarmour/fuzzing/fuzzing.py +++ b/mindarmour/fuzzing/fuzzing.py @@ -117,21 +117,21 @@ class Fuzzer: 'Noise'] self._attacks_list = ['FGSM', 'PGD', 'MDIIM'] self._attack_param_checklists = { - 'FGSM': {'params': {'eps': {'dtype': [float, int], 'range': [0, 1]}, - 'alpha': {'dtype': [float, int], + 'FGSM': {'params': {'eps': {'dtype': [float], 'range': [0, 1]}, + 'alpha': {'dtype': [float], 'range': [0, 1]}, - 'bounds': {'dtype': [list, tuple]}}}, - 'PGD': {'params': {'eps': {'dtype': [float, int], 'range': [0, 1]}, - 'eps_iter': {'dtype': [float, int], - 'range': [0, 1e5]}, - 'nb_iter': {'dtype': [float, int], + 'bounds': {'dtype': [tuple]}}}, + 'PGD': {'params': {'eps': {'dtype': [float], 'range': [0, 1]}, + 'eps_iter': {'dtype': [float], + 'range': [0, 1]}, + 'nb_iter': {'dtype': [int], 'range': [0, 1e5]}, - 'bounds': {'dtype': [list, tuple]}}}, + 'bounds': {'dtype': [tuple]}}}, 'MDIIM': { - 'params': {'eps': {'dtype': [float, int], 'range': [0, 1]}, + 'params': {'eps': {'dtype': [float], 'range': [0, 1]}, 'norm_level': {'dtype': [str]}, - 'prob': {'dtype': [float, int], 'range': [0, 1]}, - 'bounds': {'dtype': [list, tuple]}}}} + 'prob': {'dtype': [float], 'range': [0, 1]}, + 'bounds': {'dtype': [tuple]}}}} def fuzzing(self, mutate_config, initial_seeds, coverage_metric='KMNC', eval_metrics='auto', max_iters=10000, mutate_num_per_seed=20): diff --git a/mindarmour/fuzzing/image_transform.py b/mindarmour/fuzzing/image_transform.py index 77ff6d0..0ba0f1f 100644 --- a/mindarmour/fuzzing/image_transform.py +++ b/mindarmour/fuzzing/image_transform.py @@ -350,8 +350,10 @@ class Translate(ImageTransform): Translate an image. Args: - x_bias ([int, float): X-direction translation, x=x+x_bias. Default: 0. - y_bias ([int, float): Y-direction translation, y=y+y_bias. Default: 0. + x_bias ([int, float): X-direction translation, x=x+x_bias*image_length. + Default: 0. + y_bias ([int, float): Y-direction translation, y=y+y_bias*image_wide. + Default: 0. """ def __init__(self, x_bias=0, y_bias=0): @@ -363,8 +365,10 @@ class Translate(ImageTransform): Set translate parameters. Args: - x_bias ([float, int]): X-direction translation, x=x+x_bias. Default: 0. - y_bias ([float, int]): Y-direction translation, y=y+y_bias. Default: 0. + x_bias ([float, int]): X-direction translation, x=x+x_bias*image_length. + Default: 0. + y_bias ([float, int]): Y-direction translation, y=y+y_bias*image_wide. + Default: 0. auto_param (bool): True if auto generate parameters. Default: False. """ self.auto_param = auto_param -- GitLab