Skip to content

Function img_to_array() gives error for JPEG on Windows #10050

@ivan-ushakov

Description

@ivan-ushakov

Hello,

I'm getting error when I use img_to_array() function for particular JPEG file. Here is stack trace:

Traceback (most recent call last):
  File "file.py", line 41, in <module>
    tf.app.run()
  File "C:\Users\...\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "file.py", line 38, in main
    print('label: ' + x.name + ', files: ' + str(load_label(x)))
  File "file.py", line 28, in load_label
    array = preprocessing.image.img_to_array(image)
  File "C:\Users\...\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\contrib\keras\python\keras\preprocessing\image.py", line 331, in img_to_array
    x = np.asarray(img, dtype=K.floatx())
  File "C:\Users\...\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\core\numeric.py", line 531, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'JpegImageFile'

Image was loaded with load_img() from same package. I found that if I try to convert image directly with NumPy and without dtype parameter like np.asarray(image) then it works.

I am using tensorflow-gpu 1.1.0 on Windows 8.1, cuda8, python3.5, pillow (for PIL).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions