Giter VIP home page Giter VIP logo

Comments (6)

jonasrauber avatar jonasrauber commented on May 19, 2024 2

@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.

jonasrauber avatar jonasrauber commented on May 19, 2024

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.

AngusG avatar AngusG commented on May 19, 2024

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.

wielandbrendel avatar wielandbrendel commented on May 19, 2024

@AngusG Can you post a minimal working example of your problem (in a new issue)? Thanks!

from foolbox.

AngusG avatar AngusG commented on May 19, 2024

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.

jonasrauber avatar jonasrauber commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.