anishathalye / neural-style

Neural style in TensorFlow! 🎨
https://anishathalye.com/an-ai-that-can-mimic-any-artist/
GNU General Public License v3.0
5.54k stars 1.52k forks source link

Error converting image #119

Closed djcopley closed 6 years ago

djcopley commented 6 years ago

When I attempt to run the neural_style on my images I receive the following error:

Traceback (most recent call last):
  File "/Users/djcopley/Documents/GitHub/NeuralStyle/neural_style.py", line 219, in <module>
    main()
  File "/Users/djcopley/Documents/GitHub/NeuralStyle/neural_style.py", line 121, in main
    content_image = imread(options.content)
  File "/Users/djcopley/Documents/GitHub/NeuralStyle/neural_style.py", line 203, in imread
    img = scipy.misc.imread(path).astype(np.float)
TypeError: float() argument must be a string or a number, not 'JpegImageFile'

I've done some digging and it looks like scipy.misc.imread is deprecated. This shouldn't however bring the program to a halt. In addition, the documentation says imread should return an np.ndarray object, however, looking at the traceback, it appears to be returning a 'JpegImageFile' object. Any thoughts to why this might be happening? I am running Mac OSX if that wasn't clear from the traceback. Thanks :)

djcopley commented 6 years ago

By breaking the method chain apart, I was able to fix this issue.

img = scipy.misc.imread(path).astype(np.float)

Is now -

img = scipy.misc.imread(path)
img = img.astype(np.float)
anishathalye commented 6 years ago

it looks like those two should be equivalent

djcopley commented 6 years ago

They do seem to be equivalent. I would think imread() would resolve to its value and then the .astype() method would be invoked, however for some reason I was getting a type error. I couldn't figure out why it was returning a 'JpegImageFile' object instead of a numpy array either. In the interim however, splitting it up seems to have done the trick.