![](/img/trans.png)
[英]fp = builtins.open(filename, "rb") filenotfounderror: [errno 2] no such file or directory:
[英]fp = builtins.open(filename, “rb”) FileNotFoundError: [Errno 2] No such file or directory:
我正在使用 flask,
在我的config.py
中,我設置了這個UPLOAD_FOLDER = '/Users/kanel/Documents/Developments/upload'
和 controller 來處理文件上傳。
@app.route('/uploaded', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
path = os.path.join(app.config['UPLOAD_FOLDER'], f.filename)
print(path)
model= ResNet50(weights='imagenet')
img = image.load_img(path, target_size=(224,224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
preds_decoded = decode_predictions(preds, top=3)[0]
print(decode_predictions(preds, top=3)[0])
f.save(path)
return render_template('uploaded.html', title='Success', predictions=preds_decoded, user_image=f.filename)
我收到了這個錯誤:
File "/opt/anaconda3/lib/python3.7/site-packages/PIL/Image.py", line 2766, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/Users/kanel/Documents/Developments/upload/chest-example.png'
我的路徑有什么問題? 據說文件不存在,但路徑在那里!
問題是該文件在您嘗試從中加載它的位置不存在。 在使用 PIL 打開它之前,您應該將文件保存到磁盤。 f.save(path)
應該在執行img = image.load_img(path, target_size=(224,224))
之前出現
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.