首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >神经网络攻击傻瓜箱(FGSM)

神经网络攻击傻瓜箱(FGSM)
EN

Stack Overflow用户
提问于 2021-03-01 12:59:20
回答 1查看 240关注 0票数 3

我试图攻击一个位于文件(model.h5)中的keras神经网络模型,并且在万事达的文档中,TensorFlowModel支持keras模型。然而,当我将它应用于我的keras模型时,我会得到一个错误。我想知道这是否是由于我使用的愚人节版本?

代码语言:javascript
复制
import foolbox
import numpy as np
import tensorflow as tf 

from foolbox.attacks import FGSM
from foolbox.criteria import Misclassification


############## Loading the model and preprocessing #####################  
tf.keras.backend.set_learning_phase(False)
model = tf.keras.load_model("model.h5") 
_, (images, labels) = tf.keras.datasets.mnist.load_data()
images = images.reshape(images.shape[0], 28, 28, 1)
images = images / 255
images = images.astype(np.float32)

######################### Attacking the model ##########################
fmodel = foolbox.models.TensorFlowModel(model, bounds=(0, 1))
attack = foolbox.attacks.FGSM(fmodel, criterion=Misclassification())
adversarial = np.array([attack(images[0], label=labels[0])])

model_predictions = model.predict(adversarial)
print('real label: {}, label prediction; {}'.format(
    labels[0], np.argmax(model_predictions)))

误差

代码语言:javascript
复制
TypeError                                 Traceback (most recent call last)

<ipython-input-28-29f5e9da9c7e> in <module>()
     27 ######################### Attacking the model ##########################
     28 
---> 29 attack = foolbox.attacks.FGSM(fmodel, criterion=Misclassification())
     30 adversarial = np.array([attack(images[0], label=labels[0])])
     31 

TypeError: __init__() missing 1 required positional argument: 'labels'
EN

回答 1

Stack Overflow用户

发布于 2021-11-15 06:48:10

就在今天,我遇到了这个问题,看到这里没有答案,我感到很难过。但我想出来了,我们走吧。

是的,这是由于你使用的愚人节版本。

在2.4.0版和3.0.0b1版之间,大脑盒将错误分类从没有参数的函数更改为需要“标签”参数的函数。使用糊状盒2.4.0可以解决这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66422617

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档