【问题标题】:image.load_img error in python, Keraspython,Keras中的image.load_img错误
【发布时间】:2018-06-09 00:50:53
【问题描述】:

我有以下代码

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)

roi.jpg 是保存在同一目录中的图像。执行后出现以下错误

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.

请帮我解决这个错误。我用过windows 10python version : Python 3.6.3 :: Anaconda custom (64-bit)

【问题讨论】:

  • 所以基本上该消息告诉您安装 PIL。你试过吗?
  • 是的,我已经安装了枕头。但没有解决。
  • @usr2564301 谢谢

标签: python python-3.x keras anaconda pillow


【解决方案1】:

您需要 PIL 模块,尝试第一个,否则尝试第二个

conda install PIL
conda install Pillow

或者如果 PIL 和 Pillow 都存在,则卸载两者并重新安装 PIL

【讨论】:

  • 我已经安装了第二个。但这不是解决方案
  • PIL 怎么样?你安装了吗?
  • conda install pil 解决环境:失败 UnsatisfiableError:发现以下规范有冲突: - pil - zict 使用“conda info ”查看每个包的依赖关系。 @johnll
  • 可以卸载 PIL 和 Pillow 并重新安装 PIL 吗?
  • @BibinJaimon 如果对您有帮助,您可以接受我的回答,谢谢。
猜你喜欢
  • 2017-08-28
  • 2017-06-07
  • 2017-08-23
  • 1970-01-01
  • 2021-03-24
  • 2021-06-17
  • 2020-04-15
  • 2017-09-18
  • 2018-09-01
相关资源
最近更新 更多