Comments (5)
Your evaluation is wrong: you have to apply the same image preprocessing that you passed to the Foolbox model. In your example above you are not applying any preprocessing when you evaluate.
from foolbox.
@wielandbrendel Now, I use the following code to get the attack examples:
adv = np.zeros((len(imList),width,width,3)) #for saving the adv images
src = np.zeros((len(imList),width,width,3)) #for saving the original images
srcLabel = np.zeros(len(imList)) #for saving the label
for j in range(len(imList)):
image = Image.open(valpath + imList[j])
image = image.resize((width,width))
image = np.asarray(image, dtype="float32")
label = mm[imList[j]] #get the label
srcLabel[j] = label
src[j] = image
ans = attack(image[:,:,::-1], label)
if ans == None:
adv[j] = image
else:
adv[j] = ans[:,:,::-1]
np.save("srcFoolbox",src)
np.save("advFoolbox",adv)
np.save("srcLabel",srcLabel)
and use the following code to test the accuracy:
keras.backend.set_learning_phase(0)
kmodel = ResNet50(weights='imagenet')
srcLabel = np.load('srcLabel.npy')
srcdata = np.load('srcFoolbox.npy')
advdata = np.load('advFoolbox.npy')
for i in range(2):
right = 0
for j in range(len(srcdata)):
if i == 0:
image = srcdata[j]
else:
image = advdata[j]
label = srcLabel[j]
x = np.expand_dims(image, axis=0)
x = preprocess_input(x)
preds = kmodel.predict(x) #the code of predicting is got from the example code of [Keras](https://keras.io/applications/#mobilenet)
print('pre-label,',preds.argmax(),label)
if preds.argmax() == label:
right += 1
print right * 1.0 / len(srcdata)
And we get the accuracy of original images is 0.675 and the adv images is 0.575.
from foolbox.
Could you count how many images DeepFool thinks it found an adversarial for? I.e. please add something like
if ans == None:
failures += 1
adv[j] = image
else:
successes += 1
adv[j] = ans[:,:,::-1]
and report the result (failures, successes).
from foolbox.
@wielandbrendel Here, 40 test images of ImageNet are used to get the attack examples, and the result of (failures, successes) is (5,35).
The images of Cifar10 and Mnist were tested and it was normal.
from foolbox.
Please check that your preprocessing is the same, i.e. that preprocess_input(x) yields the same as fmodel._process_input(x).
from foolbox.
Related Issues (20)
- Example Code Running Failed HOT 1
- [tests/test_models] The results of `transform_bounds` are inconsistent between CPU and GPU. HOT 3
- Are there any plans to support attacks on TFLite models? HOT 1
- Changing CUDA device at runtime HOT 1
- Logit optimization
- about PGD attack HOT 2
- specifying criterion fails with TypeError HOT 2
- "nll_loss_forward_no_reduce_cuda_kernel_index" not implemented for 'Float' HOT 3
- Deprecation warning using old scipy namespace for gaussian_filter
- how to define the bounds HOT 2
- About the pgd attacks HOT 1
- how to use GaussianBlurAttack HOT 1
- FGSM TargetedMisclassfication HOT 1
- Use foolbox for multi-label classification HOT 1
- Local datasets supported?
- Is there a criterion for query budget? HOT 1
- It seems like the 'success' value in the return of the 'attack' function is overconfident. HOT 2
- About Carlini-Wagner Attack
- Are the wrong classified images sorted out? HOT 1
- It seems your CI/CD has a bug. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foolbox.