gpt4 book ai didi

python-3.x - 值错误 : Could not find a format to read the specified file in mode 'i'

转载 作者:行者123 更新时间:2023-12-03 15:04:35 24 4
gpt4 key购买 nike

我正在尝试将一个 png 文件读入在 docker 中运行的 python-flask 应用程序中,并收到一个错误消息

ValueError: Could not find a format to read the specified file in mode 'i'



我已经使用 HTML 文件上传了一个文件,现在我正在尝试读取它以进行进一步处理。我看到 scipy.misc.imread 已被弃用,我正在尝试用 imageio.imread 替换它
if request.method=='POST':
file = request.files['image']
if not file:
return render_template('index.html', label="No file")
#img = misc.imread(file)
img = imageio.imread(file)

我收到此错误:
File "./appimclass.py", line 34, in make_prediction

img = imageio.imread(file)

File "/usr/local/lib/python3.6/site-packages/imageio/core/functions.py", line 221, in imread

reader = read(uri, format, "i", **kwargs)

File "/usr/local/lib/python3.6/site-packages/imageio/core/functions.py", line 139, in get_reader

"Could not find a format to read the specified file " "in mode %r" % mode

最佳答案

最近遇到了完全相同的问题,问题是单个损坏的文件。最好是使用类似 PIL 的东西来检查坏文件。

import os
from os import listdir
from PIL import Image

dir_path = "/path/"


for filename in listdir(dir_path):
if filename.endswith('.jpg'):
try:
img = Image.open(base_dir+"\\"+filename) # open the image file
img.verify() # verify that it is, in fact an image
except (IOError, SyntaxError) as e:
print('Bad file:', filename)
#os.remove(base_dir+"\\"+filename) (Maybe)

关于python-3.x - 值错误 : Could not find a format to read the specified file in mode 'i' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54379176/

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