Comments (6)
@wielandbrendel We certainly have to rename the parameters and move image-specific ones (e.g. channel_axis) to the attacks that need it along with refactoring the preprocessing (e.g. reversing axes like channel order) and adding support for different prediction types / gradients / losses. I plan to work on this next month.
@AngusG Nevertheless, I don't see why a simple dense net shouldn't work the way it is right now. For me, this works:
import foolbox
import tensorflow as tf
import numpy as np
inputs = tf.placeholder(tf.float32, shape=(None, 784))
logits = tf.layers.dense(inputs, 10)
init_op = tf.global_variables_initializer()
np.random.seed(2)
W = np.random.rand(784, 10).astype(np.float32)
assign_op = tf.assign(tf.global_variables()[0], W)
np.random.seed(22)
example_input = np.random.rand(784)
with foolbox.models.TensorFlowModel(inputs, logits, (0, 1)) as model:
attack = foolbox.attacks.FGSM(model)
model.session.run(init_op)
model.session.run(assign_op) # replace with restorer
example_label = np.argmax(model.predictions(example_input))
print(example_label)
adversarial = attack(example_input, example_label, unpack=False)
print(np.argmax(model.predictions(adversarial.image)))
print(adversarial.distance)
outputs
7
9
rel. MSE = 0.01427 %
from foolbox.
Along with that we should analyze where the code is image-specific. For that it would be great to have an actual use-case.
from foolbox.
I found TensorFlowModel to be image/cnn specific. I wanted to import a dense net for MNIST w/ input shape (batch_size, 784) but it ended up being easier to just use a conv architechture.
from foolbox.
@AngusG Can you post a minimal working example of your problem (in a new issue)? Thanks!
from foolbox.
Thanks for the example @jonasrauber. The wrapper is not cnn specific as I suspected, although I'm unsure as to why the default setting of channel_axis=3
works for input data with less than 3 axis. This also implies to me that the wrapper accepts data of shape [batch_size, h, w, channels]
but a batch dimension of one is added automatically in models/base -- predictions(self, image).
Generally my data already has a batch dimension, e.g
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets(<data_dir>, dtype=tf.float32, one_hot=True)
image, label = mnist.test.next_batch(batch_size)
image
has shape (batch_size, 784)
here.
Reshaping to image.reshape(784)
works (for a batch_size of 1). A simple check to see if there is already a batch dimension would be a nice. I don't know why I was looking for a workaround before where I could leave the shape as-is.
What would be involved to enable batch_predictions
? This is something I might be interested in contributing.
from foolbox.
As you already figured out yourself, batch_predictions
is already supported: #57
Regarding the channel_axis
: the default setting to 3 doesn't produce an error even if there is no such dimension because the channel_axis is only used by some image-specific attacks (only for those, you will see an error); in the future, we will remove channel_axis
and other image-specific code / parameter names …
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.