當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。