“Could not import PIL.Image. The use of array_to_img requires PIL.”错误的解决办法

基于dataset\training_set数据,根据提供的结构,建立CNN模型,识别图片中的猫/狗,计算预测准确率:
1.识别图片中的猫/狗、计算dataset\test_set测试数据预测准确率
2.从网站下载猫/狗图片,对其进行预测

在构建CNN模型识别图片中的猫/狗时,通过tensorflow框架下的keras 中的load_img()加载图片时,出现了如下的错误:

ImportError: Could not import PIL.Image. The use of array_to_img requires PIL.Image

通过上网寻找解决办法,并亲自试过,特将解决办法整理如下:
主要原因是没有安装pillow,因为使用load_img()函数需要pillow

(base) C:\Users\Administrator>activate tensorflow
(tensorflow) C:\Users\Administrator>pip3 install pillow
Collecting pillow
  Downloading Pillow-7.2.0-cp36-cp36m-win_amd64.whl (2.0 MB)
     |████████████████████████████████| 2.0 MB 7.4 kB/s
Installing collected packages: pillow
Successfully installed pillow-7.2.0

问题得以解决。

参考
1.ImportError: Could not import PIL.Image. The use of array_to_img requires PIL.
2.ImportError: Could not import PIL.Image. The use of array_to_img requires PIL.

猜你喜欢

转载自blog.csdn.net/weixin_45656790/article/details/108931026