本文整理汇总了Python中cleverhans.attacks.MomentumIterativeMethod方法的典型用法代码示例。如果您正苦于以下问题:Python attacks.MomentumIterativeMethod方法的具体用法?Python attacks.MomentumIterativeMethod怎么用?Python attacks.MomentumIterativeMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cleverhans.attacks
的用法示例。
在下文中一共展示了attacks.MomentumIterativeMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_adv_examples
# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MomentumIterativeMethod [as 别名]
def create_adv_examples(model, input_t, x_to_adv, attack_dict):
"""
This fn may seem bizarre and pointless, but the point of it is to
enable the entire attack to be specified as a dict from the command line without
editing this script, which is convenient for storing the settings used for an attack
"""
if attack_dict['method'] == 'fgm':
attack = attacks.FastGradientMethod(model, sess=K.get_session(), back='tf')
elif attack_dict['method'] == 'bim':
attack = attacks.BasicIterativeMethod(model, sess=K.get_session(), back='tf')
elif attack_dict['method'] == 'mim':
attack = attacks.MomentumIterativeMethod(model, sess=K.get_session(), back='tf')
else:
assert False, 'Current attack needs to be added to the create attack fn'
adv_tensor = attack.generate(input_t, **{k: a for k, a in attack_dict.items() if
k != 'method'}) # 'method' key for this fn use
x_adv = batch_eval(adv_tensor, input_t, x_to_adv, batch_size=args.batch_size, verbose="Generating adv examples")
return x_adv
示例2: setUp
# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MomentumIterativeMethod [as 别名]
def setUp(self):
super(TestMomentumIterativeMethod, self).setUp()
self.sess = tf.Session()
self.model = SimpleModel()
self.attack = MomentumIterativeMethod(self.model, sess=self.sess)
示例3: setUp
# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import MomentumIterativeMethod [as 别名]
def setUp(self):
super(TestMomentumIterativeMethod, self).setUp()
self.attack = MomentumIterativeMethod(self.model, sess=self.sess)