當前位置: 首頁>>代碼示例>>Python>>正文


Python model.CallableModelWrapper方法代碼示例

本文整理匯總了Python中cleverhans.model.CallableModelWrapper方法的典型用法代碼示例。如果您正苦於以下問題:Python model.CallableModelWrapper方法的具體用法?Python model.CallableModelWrapper怎麽用?Python model.CallableModelWrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cleverhans.model的用法示例。


在下文中一共展示了model.CallableModelWrapper方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, back='tf', sess=None, dtypestr='float32'):
        """
        Create a FastGradientMethod instance.
        Note: the model parameter should be an instance of the
        cleverhans.model.Model abstraction provided by CleverHans.
        """
        if not isinstance(model, Model):
            model = CallableModelWrapper(model, 'probs')

        super(FastGradientMethod, self).__init__(model, back, sess, dtypestr)
        self.feedable_kwargs = {
            'eps': self.np_dtype,
            'y': self.np_dtype,
            'y_target': self.np_dtype,
            'clip_min': self.np_dtype,
            'clip_max': self.np_dtype
        }
        self.structural_kwargs = ['ord'] 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:20,代碼來源:attacks.py

示例2: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, back='tf', sess=None, dtypestr='float32'):
        """
        Create a BasicIterativeMethod instance.
        Note: the model parameter should be an instance of the
        cleverhans.model.Model abstraction provided by CleverHans.
        """
        if not isinstance(model, Model):
            model = CallableModelWrapper(model, 'probs')

        super(BasicIterativeMethod, self).__init__(model, back, sess, dtypestr)
        self.feedable_kwargs = {
            'eps': self.np_dtype,
            'eps_iter': self.np_dtype,
            'y': self.np_dtype,
            'y_target': self.np_dtype,
            'clip_min': self.np_dtype,
            'clip_max': self.np_dtype
        }
        self.structural_kwargs = ['ord', 'nb_iter'] 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:21,代碼來源:attacks.py

示例3: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, back='tf', sess=None, dtypestr='float32'):
    """
    Create a SpatialTransformationMethod instance.
    Note: the model parameter should be an instance of the
    cleverhans.model.Model abstraction provided by CleverHans.
    """
    if not isinstance(model, Model):
      model = CallableModelWrapper(model, 'probs')

    super(SpatialTransformationMethod, self).__init__(
      model, back, sess, dtypestr)
    self.feedable_kwargs = {
      'n_samples': self.np_dtype,
      'dx_min': self.np_dtype,
      'dx_max': self.np_dtype,
      'n_dxs': self.np_dtype,
      'dy_min': self.np_dtype,
      'dy_max': self.np_dtype,
      'n_dys': self.np_dtype,
      'angle_min': self.np_dtype,
      'angle_max': self.np_dtype,
      'n_angles': self.np_dtype,
      'black_border_size': self.np_dtype,
    } 
開發者ID:google,項目名稱:unrestricted-adversarial-examples,代碼行數:26,代碼來源:cleverhans_fast_spatial_attack.py

示例4: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, sess, dtypestr='float32', **kwargs):
    """
    Note: the model parameter should be an instance of the
    cleverhans.model.Model abstraction provided by CleverHans.
    """
    if not isinstance(model, Model):
      wrapper_warning_logits()
      model = CallableModelWrapper(model, 'logits')

    super(CarliniWagnerL2, self).__init__(model, sess, dtypestr, **kwargs)

    self.feedable_kwargs = ('y', 'y_target')

    self.structural_kwargs = [
        'batch_size', 'confidence', 'targeted', 'learning_rate',
        'binary_search_steps', 'max_iterations', 'abort_early',
        'initial_const', 'clip_min', 'clip_max'
    ] 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:20,代碼來源:carlini_wagner_l2.py

示例5: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, sess, dtypestr='float32', **kwargs):
    """
    Note: the model parameter should be an instance of the
    cleverhans.model.Model abstraction provided by CleverHans.
    """
    if not isinstance(model, Model):
      wrapper_warning_logits()
      model = CallableModelWrapper(model, 'logits')

    super(ElasticNetMethod, self).__init__(model, sess, dtypestr, **kwargs)

    self.feedable_kwargs = ('y', 'y_target')

    self.structural_kwargs = [
        'beta', 'decision_rule', 'batch_size', 'confidence',
        'targeted', 'learning_rate', 'binary_search_steps',
        'max_iterations', 'abort_early', 'initial_const', 'clip_min',
        'clip_max'
    ] 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:21,代碼來源:elastic_net_method.py

示例6: test_output_layer

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def test_output_layer(self):
        def model(**kwargs):
            del kwargs
            return True

        # The following two calls should not raise Exceptions
        wrap = CallableModelWrapper(model, 'probs')
        wrap = CallableModelWrapper(model, 'logits') 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:10,代碼來源:test_model.py

示例7: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, m, back='tf', sess=None):
    if not isinstance(m, model.Model):
      m = model.CallableModelWrapper(m, 'probs')

    super(RandomAttack, self).__init__(m, back, sess)
    self.feedable_kwargs = {
        'eps': np.float32,
        'num_samples': np.float32,
        'num_batches': np.float32,
        'y': np.float32,
        'y_target': np.float32,
        'clip_min': np.float32,
        'clip_max': np.float32
    }
    self.structural_kwargs = ['ord'] 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:17,代碼來源:adv_attack_utils.py

示例8: spsa_attack

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def spsa_attack():
    # Use tf for evaluation on adversarial data
    sess = tf.Session()
    x_op = tf.placeholder(tf.float32, shape=(None, 3, 32, 32,))
    y_op = tf.placeholder(tf.float32, shape=(1,))

    # Convert pytorch model to a tf_model and wrap it in cleverhans
    tf_model_fn = convert_pytorch_model_to_tf(menet_model)
    cleverhans_model = CallableModelWrapper(tf_model_fn, output_layer='logits')

    # Create an SPSA attack
    spsa = SPSA(cleverhans_model, sess=sess)
    spsa_params = {
        'eps': config['epsilon'],
        'nb_iter': config['num_steps'],
        'clip_min': 0.,
        'clip_max': 1.,
        'spsa_samples': args.spsa_sample,  # in this case, the batch_size is equal to spsa_samples
        'spsa_iters': 1,
    }

    adv_x_op = spsa.generate(x_op, y_op, **spsa_params)
    adv_preds_op = tf_model_fn(adv_x_op)

    # Evaluation against SPSA attacks
    correct = 0
    total = 0
    for batch_idx, (inputs, targets) in enumerate(test_loader):
        adv_preds = sess.run(adv_preds_op, feed_dict={x_op: inputs, y_op: targets})
        correct += (np.argmax(adv_preds, axis=1) == targets).sum().float()
        total += len(inputs)

        sys.stdout.write(
            "\rBlack-box SPSA attack... Acc: %.3f%% (%d/%d)" % (100. * correct / total, correct, total))
        sys.stdout.flush()

    print('Accuracy under SPSA attack: %.3f%%' % (100. * correct / total)) 
開發者ID:YyzHarry,項目名稱:ME-Net,代碼行數:39,代碼來源:attack_blackbox.py

示例9: test_output_layer

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def test_output_layer(self):
    """
    Test that the CallableModelWrapper can be constructed without causing Exceptions
    """
    def model(**kwargs):
      """Mock model"""
      del kwargs
      return True

    # The following two calls should not raise Exceptions
    CallableModelWrapper(model, 'probs')
    CallableModelWrapper(model, 'logits') 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:14,代碼來源:test_model.py

示例10: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, dtypestr='float32', **kwargs):
    """
    Creates a FastGradientMethod instance in eager execution.
    :model: cleverhans.model.Model
    :dtypestr: datatype in the string format.
    """
    del kwargs
    if not isinstance(model, Model):
      wrapper_warning()
      model = CallableModelWrapper(model, 'probs')

    super(FastGradientMethod, self).__init__(model, dtypestr) 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:14,代碼來源:attacks_tfe.py

示例11: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, sess=None, dtypestr='float32', **kwargs):
    """
    Note: the model parameter should be an instance of the
    cleverhans.model.Model abstraction provided by CleverHans.
    """
    if not isinstance(model, Model):
      wrapper_warning_logits()
      model = CallableModelWrapper(model, 'logits')

    super(VirtualAdversarialMethod, self).__init__(model, sess, dtypestr,
                                                   **kwargs)

    self.feedable_kwargs = ('eps', 'xi', 'clip_min', 'clip_max')
    self.structural_kwargs = ['num_iterations'] 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:16,代碼來源:virtual_adversarial_method.py

示例12: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import CallableModelWrapper [as 別名]
def __init__(self, model, sess, dtypestr='float32', **kwargs):
    """
    Create a DeepFool instance.
    """
    if not isinstance(model, Model):
      wrapper_warning_logits()
      model = CallableModelWrapper(model, 'logits')

    super(DeepFool, self).__init__(model, sess, dtypestr, **kwargs)

    self.structural_kwargs = [
        'overshoot', 'max_iter', 'clip_max', 'clip_min', 'nb_candidate'
    ] 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:15,代碼來源:deep_fool.py


注:本文中的cleverhans.model.CallableModelWrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。