当前位置: 首页>>代码示例>>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;未经允许,请勿转载。