Bibin Jaimon
Bibin Jaimon

Reputation: 592

image.load_img error in python, Keras

I have the following code

from keras.preprocessing import image
    test_image = image.load_img('roi.jpg', target_size = (64, 64),grayscale=True)
    test_image = image.img_to_array(test_image)
    test_image = np.expand_dims(test_image, axis = 0)

The roi.jpg is an image which saved in the same directory. After execution I got the following error

test_image = image.load_img('roi.jpg', target_size = (64, 64),grayscale=True)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\preprocessing\image.py", line 345, in load_img raise ImportError('Could not import PIL.Image. ')
ImportError: Could not import PIL.Image. The use of `array_to_img` requires PIL.

Please help me to solve this error. I have used windows 10 and python version : Python 3.6.3 :: Anaconda custom (64-bit)

Upvotes: 3

Views: 18886

Answers (1)

johnII
johnII

Reputation: 1433

You need the PIL module, try the first one else try the second one

conda install PIL
conda install Pillow

or if both PIL and Pillow exists, uninstall both and re-install PIL

Upvotes: 3

Related Questions