image.load_img error in python, Keras

14,683

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

Share:
14,683
Bibin Jaimon
Author by

Bibin Jaimon

Software Engineer with over 4 years of industry experience. Platform: iOS Tech: Swift, JavaScript Frameworks: Cocoa Touch, React Native Tools: XCode, VSCode

Updated on June 04, 2022

Comments

  • Bibin Jaimon
    Bibin Jaimon almost 2 years

    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)

  • Bibin Jaimon
    Bibin Jaimon over 6 years
    i have already installed the second one. but that's not the solution
  • johnII
    johnII over 6 years
    how about PIL? have you installed it?
  • Bibin Jaimon
    Bibin Jaimon over 6 years
    conda install pil Solving environment: failed UnsatisfiableError: The following specifications were found to be in conflict: - pil - zict Use "conda info <package>" to see the dependencies for each package. @johnll
  • johnII
    johnII over 6 years
    can you uninstall PIL and Pillow and install PIL again?
  • johnII
    johnII over 6 years
    @BibinJaimon you can accept my answer if it helped you, thanks.