当前位置: 首页>>代码示例>>Python>>正文


Python attacks.DeepFool方法代码示例

本文整理汇总了Python中cleverhans.attacks.DeepFool方法的典型用法代码示例。如果您正苦于以下问题:Python attacks.DeepFool方法的具体用法?Python attacks.DeepFool怎么用?Python attacks.DeepFool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cleverhans.attacks的用法示例。


在下文中一共展示了attacks.DeepFool方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import DeepFool [as 别名]
def setUp(self):
        super(TestDeepFool, self).setUp()

        self.sess = tf.Session()
        self.model = SimpleModel()
        self.attack = DeepFool(self.model, sess=self.sess) 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:8,代码来源:test_attacks.py

示例2: query

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import DeepFool [as 别名]
def query(self, X_train, Y_train, labeled_idx, amount):

        unlabeled_idx = get_unlabeled_idx(X_train, labeled_idx)
        unlabeled = X_train[unlabeled_idx]

        keras_wrapper = KerasModelWrapper(self.model)
        sess = K.get_session()
        deep_fool = DeepFool(keras_wrapper, sess=sess)
        deep_fool_params = {'over_shoot': 0.02,
                            'clip_min': 0.,
                            'clip_max': 1.,
                            'nb_candidate': Y_train.shape[1],
                            'max_iter': 10}
        true_predictions = np.argmax(self.model.predict(unlabeled, batch_size=256), axis=1)
        adversarial_predictions = np.copy(true_predictions)
        while np.sum(true_predictions != adversarial_predictions) < amount:
            adversarial_images = np.zeros(unlabeled.shape)
            for i in range(0, unlabeled.shape[0], 100):
                print("At {i} out of {n}".format(i=i, n=unlabeled.shape[0]))
                if i+100 > unlabeled.shape[0]:
                    adversarial_images[i:] = deep_fool.generate_np(unlabeled[i:], **deep_fool_params)
                else:
                    adversarial_images[i:i+100] = deep_fool.generate_np(unlabeled[i:i+100], **deep_fool_params)
            pertubations = adversarial_images - unlabeled
            norms = np.linalg.norm(np.reshape(pertubations,(unlabeled.shape[0],-1)), axis=1)
            adversarial_predictions = np.argmax(self.model.predict(adversarial_images, batch_size=256), axis=1)
            norms[true_predictions == adversarial_predictions] = np.inf
            deep_fool_params['max_iter'] *= 2

        selected_indices = np.argpartition(norms, amount)[:amount]

        del keras_wrapper
        del deep_fool
        gc.collect()

        return np.hstack((labeled_idx, unlabeled_idx[selected_indices])) 
开发者ID:dsgissin,项目名称:DiscriminativeActiveLearning,代码行数:38,代码来源:query_methods.py

示例3: setUp

# 需要导入模块: from cleverhans import attacks [as 别名]
# 或者: from cleverhans.attacks import DeepFool [as 别名]
def setUp(self):
    super(TestDeepFool, self).setUp()

    self.sess = tf.Session()
    self.model = SimpleModel()
    self.attack = DeepFool(self.model, sess=self.sess) 
开发者ID:tensorflow,项目名称:cleverhans,代码行数:8,代码来源:test_attacks.py


注:本文中的cleverhans.attacks.DeepFool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。