当前位置: 首页>>代码示例>>Python>>正文


Python attacks.MadryEtAl方法代码示例

本文整理汇总了Python中cleverhans.attacks.MadryEtAl方法的典型用法代码示例。如果您正苦于以下问题:Python attacks.MadryEtAl方法的具体用法?Python attacks.MadryEtAl怎么用?Python attacks.MadryEtAl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cleverhans.attacks的用法示例。


在下文中一共展示了attacks.MadryEtAl方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MadryEtAl [as 别名]
def setUp(self):
        super(TestMadryEtAl, self).setUp()

        self.sess = tf.Session()
        self.model = SimpleModel()
        self.attack = MadryEtAl(self.model, sess=self.sess) 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:8,代码来源:test_attacks.py

示例2: parse_params

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MadryEtAl [as 别名]
def parse_params(self, ngpu=1, **kwargs):
        """
        Take in a dictionary of parameters and applies attack-specific checks
        before saving them as attributes.

        Attack-specific parameters:
        :param ngpu: (required int) the number of GPUs available.
        :param kwargs: A dictionary of parameters for MadryEtAl attack.
        """

        return_status = super(MadryEtAlMultiGPU, self).parse_params(**kwargs)
        self.ngpu = ngpu

        return return_status 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:16,代码来源:attacks_multigpu.py

示例3: return_paras

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MadryEtAl [as 别名]
def return_paras(model_name):
    if model_name == 'SCE':
        return 0, None, False, False, False, False, 0.0, True
    elif model_name == 'MMC-10':
        return 10.0, None, False, True, True, False, 0.0, False
    elif model_name == 'MMC-100':
        return 100.0, None, False, True, True, False, 0.0, False
    elif model_name == 'AT-SCE':
        return 0, 'MadryEtAl', True, False, False, True, 1.0, True
    elif model_name == 'AT-MMC-10':
        return 10, 'MadryEtAl', True, True, True, True, 1.0, False
    elif model_name == 'AT-MMC-100':
        return 100, 'MadryEtAl', True, True, True, True, 1.0, False
    else:
        return None 
开发者ID:P2333,项目名称:Max-Mahalanobis-Training,代码行数:17,代码来源:advtest_iterative_blackbox.py

示例4: test_attack_can_be_constructed

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MadryEtAl [as 别名]
def test_attack_can_be_constructed(self):
    # The test passes if this does not raise an exception
    self.attack = MadryEtAl(self.model, sess=self.sess) 
开发者ID:tensorflow,项目名称:cleverhans,代码行数:5,代码来源:test_attacks.py

示例5: parse_params

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MadryEtAl [as 别名]
def parse_params(self, ngpu=1, **kwargs):
    """
    Take in a dictionary of parameters and applies attack-specific checks
    before saving them as attributes.

    Attack-specific parameters:
    :param ngpu: (required int) the number of GPUs available.
    :param kwargs: A dictionary of parameters for MadryEtAl attack.
    """

    return_status = super(MadryEtAlMultiGPU, self).parse_params(**kwargs)
    self.ngpu = ngpu

    return return_status 
开发者ID:tensorflow,项目名称:cleverhans,代码行数:16,代码来源:attacks_multigpu.py

示例6: create_adv_by_name

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MadryEtAl [as 别名]
def create_adv_by_name(model, x, attack_type, sess, dataset, y=None, **kwargs):
    """
    Creates the symbolic graph of an adversarial example given the name of
    an attack. Simplifies creating the symbolic graph of an attack by defining
    dataset-specific parameters.
    Dataset-specific default parameters are used unless a different value is
    given in kwargs.

    :param model: an object of Model class
    :param x: Symbolic input to the attack.
    :param attack_type: A string that is the name of an attack.
    :param sess: Tensorflow session.
    :param dataset: The name of the dataset as a string to use for default
                   params.
    :param y: (optional) a symbolic variable for the labels.
    :param kwargs: (optional) additional parameters to be passed to the attack.
    """
    # TODO: black box attacks
    attack_names = {'FGSM': FastGradientMethod,
                    'MadryEtAl': MadryEtAl,
                    'MadryEtAl_y': MadryEtAl,
                    'MadryEtAl_multigpu': MadryEtAlMultiGPU,
                    'MadryEtAl_y_multigpu': MadryEtAlMultiGPU,
                    }

    if attack_type not in attack_names:
        raise Exception('Attack %s not defined.' % attack_type)

    attack_params_shared = {
        'mnist': {'eps': .3, 'eps_iter': 0.01, 'clip_min': 0., 'clip_max': 1.,
                  'nb_iter': 40},
        'cifar10': {'eps': 8./255, 'eps_iter': 0.01, 'clip_min': 0.,
                    'clip_max': 1., 'nb_iter': 20}
    }

    with tf.variable_scope(attack_type):
        attack_class = attack_names[attack_type]
        attack = attack_class(model, sess=sess)

        # Extract feedable and structural keyword arguments from kwargs
        fd_kwargs = attack.feedable_kwargs.keys() + attack.structural_kwargs
        params = attack_params_shared[dataset].copy()
        params.update({k: v for k, v in kwargs.items() if v is not None})
        params = {k: v for k, v in params.items() if k in fd_kwargs}

        if '_y' in attack_type:
            params['y'] = y
        logging.info(params)
        adv_x = attack.generate(x, **params)

    return adv_x 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:53,代码来源:evaluator.py

示例7: create_adv_by_name

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MadryEtAl [as 别名]
def create_adv_by_name(model, x, attack_type, sess, dataset, y=None, **kwargs):
  """
  Creates the symbolic graph of an adversarial example given the name of
  an attack. Simplifies creating the symbolic graph of an attack by defining
  dataset-specific parameters.
  Dataset-specific default parameters are used unless a different value is
  given in kwargs.

  :param model: an object of Model class
  :param x: Symbolic input to the attack.
  :param attack_type: A string that is the name of an attack.
  :param sess: Tensorflow session.
  :param dataset: The name of the dataset as a string to use for default
                 params.
  :param y: (optional) a symbolic variable for the labels.
  :param kwargs: (optional) additional parameters to be passed to the attack.
  """
  # TODO: black box attacks
  attack_names = {'FGSM': FastGradientMethod,
                  'MadryEtAl': MadryEtAl,
                  'MadryEtAl_y': MadryEtAl,
                  'MadryEtAl_multigpu': MadryEtAlMultiGPU,
                  'MadryEtAl_y_multigpu': MadryEtAlMultiGPU
                 }

  if attack_type not in attack_names:
    raise Exception('Attack %s not defined.' % attack_type)

  attack_params_shared = {
      'mnist': {'eps': .3, 'eps_iter': 0.01, 'clip_min': 0., 'clip_max': 1.,
                'nb_iter': 40},
      'cifar10': {'eps': 8./255, 'eps_iter': 0.01, 'clip_min': 0.,
                  'clip_max': 1., 'nb_iter': 20}
  }

  with tf.variable_scope(attack_type):
    attack_class = attack_names[attack_type]
    attack = attack_class(model, sess=sess)

    # Extract feedable and structural keyword arguments from kwargs
    fd_kwargs = attack.feedable_kwargs.keys() + attack.structural_kwargs
    params = attack_params_shared[dataset].copy()
    params.update({k: v for k, v in kwargs.items() if v is not None})
    params = {k: v for k, v in params.items() if k in fd_kwargs}

    if '_y' in attack_type:
      params['y'] = y
    logging.info(params)
    adv_x = attack.generate(x, **params)

  return adv_x 
开发者ID:tensorflow,项目名称:cleverhans,代码行数:53,代码来源:evaluator.py


注:本文中的cleverhans.attacks.MadryEtAl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。