Hyperparticle / one-pixel-attack-keras

Keras implementation of "One pixel attack for fooling deep neural networks" using differential evolution on Cifar10 and ImageNet
https://arxiv.org/abs/1710.08864
MIT License
1.22k stars 214 forks source link

SyntaxError: invalid syntax #6

Closed ghghgh0001 closed 6 years ago

ghghgh0001 commented 6 years ago

File "helper.py", line 32 x_pos, y_pos, *rgb = pixel ^ SyntaxError: invalid syntax I met this problem while running the "imports" of "1_one-pixel-attack-cifar10", with both python2 and python3.

ghghgh0001 commented 6 years ago

I delete the "*" before "rgb", and it works, is it correct? It's not correct. I change them to : x_pos, y_pos, r, g, b = pixel img[x_pos, y_pos] = [r, g, b] seems ok.

Hyperparticle commented 6 years ago

It seems that you're running a version of Python that does not support Extended Iterable Unpacking. According to this StackOverflow post, it should work with Python 3.0+.

Are you sure you are running with Python 3? There shouldn't be a syntax error in that case. You can check by writing the following code in a cell:

import platform
print(platform.python_version()) # Should be 3.x.x

If you are still running across this issue, the code

x_pos, y_pos, r, g, b = pixel
img[x_pos, y_pos] = r, g, b

should be equivalent.

ghghgh0001 commented 6 years ago

I changed the kernel of jupyter to python3, but it doesn't work, and I updated my jupyter, but it still no use.

x_pos, y_pos, r, g, b = pixel img[x_pos, y_pos] = [r, g, b]

I write them like this, is it the same?

ghghgh0001 commented 6 years ago

I change the kernal of jupyter to python3, but it still 2.7.12, seems something wrong with my jupyter. I copy the code to a .py file, and use python3 to open it in the terminal, and there's no problem now. Thanks for answering my silly problem. :)