【发布时间】:2017-07-16 16:33:26
【问题描述】:
我正在尝试使用 Keras 的 Image 包读取图像文件。
这是我的代码。
from keras.preprocessing import image
img_path = 'test/test_image.jpg' # This is an image I took in my kitchen.
img = image.load_img(img_path, target_size=(224, 224))
当我运行代码时,我收到以下错误。
anaconda3/lib/python3.5/site-packages/PIL/ImageFile.py in load(self)
238 if not self.map and not LOAD_TRUNCATED_IMAGES and err_code < 0:
239 # still raised if decoder fails to return anything
--> 240 raise_ioerror(err_code)
241
242 # post processing
anaconda3/lib/python3.5/site-packages/PIL/ImageFile.py in raise_ioerror(error)
57 if not message:
58 message = "decoder error %d" % error
---> 59 raise IOError(message + " when reading image file")
60
61
OSError: broken data stream when reading image file
请注意,如果我将test_image.jpg 转换为test_image.png,那么给定的代码可以完美运行。但是我有几千张图片,我无法将它们全部转换为 png 格式。在网上搜索解决方案后,我尝试了几件事,但无法摆脱问题。
任何帮助将不胜感激!
【问题讨论】:
标签: python-3.5 keras