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


Python model.Model方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [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 Model [as 別名]
def __init__(self, model, dtypestr='float32'):
        """
        :param model: An instance of the cleverhans.model.Model class.
        :param back: The backend to use. Inherited from AttackBase class.
        :param dtypestr: datatype of the input data samples and crafted
                        adversarial attacks.
        """
        # Validate the input arguments.
        if dtypestr != 'float32' and dtypestr != 'float64':
            raise ValueError("Unexpected input for argument dtypestr.")
        import tensorflow as tf
        tfe = tf.contrib.eager
        self.tf_dtype = tf.as_dtype(dtypestr)
        self.np_dtype = np.dtype(dtypestr)

        if not isinstance(model, Model):
            raise ValueError("The model argument should be an instance of"
                             " the cleverhans.model.Model class.")
        # Prepare attributes
        self.model = model
        self.dtypestr = dtypestr 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:23,代碼來源:attacks_tfe.py

示例3: fprop

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [as 別名]
def fprop(self, x):
    if x.name in self._logits_dict:
      return self._logits_dict[x.name]

    x = tf.map_fn(tf.image.per_image_standardization, x)
    self._additional_features['inputs'] = x

    if self._scope is None:
      scope = tf.variable_scope(tf.get_variable_scope(), reuse=tf.AUTO_REUSE)
    else:
      scope = tf.variable_scope(self._scope, reuse=tf.AUTO_REUSE)

    with scope:
      logits = self._model_fn(
          self._additional_features,
          None,
          'attack',
          params=self._params,
          config=self._config)
    self._logits_dict[x.name] = logits

    return {model.Model.O_LOGITS: tf.reshape(logits, [-1, logits.shape[-1]])} 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:24,代碼來源:adv_attack_utils.py

示例4: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [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

示例5: test_no_logits

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [as 別名]
def test_no_logits():
  """test_no_logits: Check that a model without logits causes an error"""
  batch_size = 2
  nb_classes = 3

  class NoLogitsModel(Model):
    """
    A model that neither defines logits nor makes it possible to find logits
    by inspecting the inputs to a softmax op.
    """

    def fprop(self, x, **kwargs):
      return {'probs': tf.ones((batch_size, nb_classes)) / nb_classes}
  model = NoLogitsModel()
  sess = tf.Session()
  attack = ProjectedGradientDescent(model, sess=sess)
  x = tf.ones((batch_size, 3))
  assert_raises(NotImplementedError, attack.generate, x) 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:20,代碼來源:test_projected_gradient_descent.py

示例6: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [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

示例7: __init__

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [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

示例8: test_get_logits

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [as 別名]
def test_get_logits(self):
        # Define empty model
        model = Model('model', 10, {})
        x = []

        # Exception is thrown when `get_logits` not implemented
        with self.assertRaises(Exception) as context:
            model.get_logits(x)
        self.assertTrue(context.exception) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:11,代碼來源:test_model.py

示例9: test_get_probs

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [as 別名]
def test_get_probs(self):
        # Define empty model
        model = Model('model', 10, {})
        x = []

        # Exception is thrown when `get_probs` not implemented
        with self.assertRaises(Exception) as context:
            model.get_probs(x)
        self.assertTrue(context.exception) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:11,代碼來源:test_model.py

示例10: test_fprop

# 需要導入模塊: from cleverhans import model [as 別名]
# 或者: from cleverhans.model import Model [as 別名]
def test_fprop(self):
        # Define empty model
        model = Model('model', 10, {})
        x = []

        # Exception is thrown when `fprop` not implemented
        with self.assertRaises(Exception) as context:
            model.fprop(x)
        self.assertTrue(context.exception) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:11,代碼來源:test_model.py


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