Python fp=builtins.open(文件名“rb”)FileNotFoundError:[Errno 2]没有这样的文件或目录:

Python fp=builtins.open(文件名“rb”)FileNotFoundError:[Errno 2]没有这样的文件或目录:,python,flask,keras,python-imaging-library,Python,Flask,Keras,Python Imaging Library,我用的是烧瓶 在myconfig.py中,我设置了 UPLOAD\u FOLDER='/Users/kanel/Documents/Developments/UPLOAD' 和控制器来处理文件上传 @app.route('/uploaded', methods = ['GET', 'POST']) def upload_file(): if request.method == 'POST': f = request.files['file'] path = os.p

我用的是烧瓶

在my
config.py
中,我设置了
UPLOAD\u FOLDER='/Users/kanel/Documents/Developments/UPLOAD'

和控制器来处理文件上传

@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\u img(path,target\u size=(224224))