gpt4 book ai didi

python-3.5 - OSError : broken data stream when reading image file

转载 作者:行者123 更新时间:2023-12-04 01:07:01 44 4
gpt4 key购买 nike

我正在尝试使用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格式。在网络中搜索解决方案后,我尝试了几种方法,但无法摆脱问题。

任何帮助,将不胜感激!

最佳答案

在代码的开头使用此命令:

from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

我找到了它 here。这正在为我工​​作。

关于python-3.5 - OSError : broken data stream when reading image file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42462431/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com