本文整理匯總了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']
示例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
示例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]])}
示例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,
}
示例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)
示例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'
]
示例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'
]
示例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)
示例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)
示例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)