I am trying to read image data into Python as a matrix.
To this extent, I am trying to use scipy.misc.imread('image.jpg').astype(np.float)
.
When I execute the proper sequence of steps from a python3
interpreter, everything works swimmingly, and I get a matrix as expected.
When I invoke the command from a script (python3 foo.py
...), however, I get an error complaining that the argument to convert via float
cannot be of type JpegImageFile
. I've ensured that I've pip install -U pillow
to ensure that PIL is available.
What gives? How could this be possible? I've verified over and over that the same lines of code are executed in each case, the only difference seems to be that the invocation inside of a script happens inside of a defined function, but even if I pdb.set_trace()
from elsewhere in the script the same results happen.
What could be causing fluctuation in results from the interpreter to the script?
EDIT: OK, to be precise, I am running the neural_style.py
script from here: https://github.com/anishathalye/neural-style . scipy
, numpy
, tensorflow
, and pillow
must be installed. I am using python3
. Any parameters for --content
, --styles
, and --output
should work to dupe the bug.
Full error traceback:
Traceback (most recent call last):
File "neural_style.py", line 150, in <module>
main()
File "neural_style.py", line 84, in main
content_image = imread(options.content)
File "neural_style.py", line 141, in imread
return scipy.misc.imread(path).astype(np.float)
TypeError: float() argument must be a string or a number, not 'JpegImageFile'
But, a small simple script such as the following actually works:
import numpy as np
import scipy.misc
print(scipy.misc.imread('content').astype(np.float))
neural_style.py
, ran it in both python 2.7 and 3.4, and it worked just fine. Either give a specific MCVE, or put add some prints toneural_style.py
to find out what it thinks all the components ofscipy.misc.imread(path).astype(np.float)
are at the time, or both.