Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in PixelThreshold for single input #1979

Closed
wants to merge 2 commits into from

Conversation

aufieroma12
Copy link
Contributor

Description

Calling .generate() on a batch of length one, a TypeError is raised on line 193.

TypeError: iteration over a 0-d array

This is because np.squeeze(y) returns a 0-dimensional array when y.shape == (1, 1). Changing it to y.flatten() solves this issue by returning a 1-dimensional array in this case, while not changing the behavior in the case when the batch has more than one input.

Fixes # (issue)

Type of change

Please check all relevant options.

  • Improvement (non-breaking)
  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing

Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.

  • Ran Pixel Attack on input array of shape (1, 3, 224, 224) (this did not work before, and it does not)
  • Ran Pixel Attack on input array of shape (3, 3, 224, 224) (this still works as before)

Test Configuration:

  • OS
  • Python version
  • ART version or commit number
  • TensorFlow / Keras / PyTorch / MXNet version

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Calling `.generate()` on a batch of length one, a `TypeError` is raised on line 193. This is because `np.squeeze(y)` returns a 0-dimensional array when `y.shape == (1, 1)`. Changing it to `y.flatten()` solves this issue by returning a 1-dimensional array in this case, while not changing the behavior in the case when the batch has more than one input.
Signed-off-by: Massimo Aufiero <aufieroma12@gmail.com>
@aufieroma12 aufieroma12 closed this Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant