Giter Club home page Giter Club logo

Comments (5)

ririnicolae avatar ririnicolae commented on August 26, 2024 1

Hi, @Jindong-Explainable-AI! I managed to reproduce your error. In the code you posted, there is an error in input_shape when you create the PyTorchClassifier object: you use (3, 244, 244) instead of (3, 224, 224). 😄 Correcting these values will allow you to use the attacks.

from adversarial-robustness-toolbox.

JindongGu avatar JindongGu commented on August 26, 2024 1

Thanks for this! Sorry for such an embarrassing error.
FastGradientMethod, BIM use loss_gradient() where assert grds.shape == x.shape
In CarliniL2Method, it uses class_gradient() where assert grds.shape == (x_.shape[0], self.nb_classes) + self.input_shape
The first one has nothing to do with the specified input shape.
That is why one works, it does not work for the other!
Okay, Thanks a lot!

from adversarial-robustness-toolbox.

ririnicolae avatar ririnicolae commented on August 26, 2024

Hi, @Jindong-Explainable-AI! The fact that you get the error for C&W and DeepFool, but not FGSM confirms that the problem comes from the implementation of class gradients for the PyTorch wrapper. A couple of questions:

  • Could you confirm that you pass input_shape=(3, 224, 224) to PyTorchClassifier when you create the object?
  • Is the model you are using one of the standard Imagenet models? This would help us reproduce the error on our side.

from adversarial-robustness-toolbox.

JindongGu avatar JindongGu commented on August 26, 2024

Hi, @Irina Nicolae Thanks for the response! I reinstalled the package again with pip command and also manually. And run the code, get the same error! I also tried with different (input_shape) e.g. (224, 224), (1, 224, 224), (1, 3, 224, 224), (3, 224, 224), (224, 224, 3) and so on, still the same error.

from adversarial-robustness-toolbox.

JindongGu avatar JindongGu commented on August 26, 2024

model = models.vgg16(pretrained=True)

classifier = PyTorchClassifier(clip_values=(-2.11790394, 2.2489084), model=model, loss= nn.CrossEntropyLoss(), optimizer= torch.optim.SGD(model.parameters(), lr = 0.01), input_shape=(3, 244, 244), nb_classes = 1000, defences = None, preprocessing=(0, 1))

adv = CarliniL2Method(classifier, targeted=False, max_iter=10, binary_search_steps=10, learning_rate=0.01)

adv.generate(img_variable.data.numpy())

the shape of img_variable.data.numpy() is (1, 3, 224, 224)

FYI to reproduce the error!

from adversarial-robustness-toolbox.

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.