Python 将PIL PNGIMAGE文件传递给tensorflow进行图像识别

Python 将PIL PNGIMAGE文件传递给tensorflow进行图像识别,python,tensorflow,flask,python-imaging-library,Python,Tensorflow,Flask,Python Imaging Library,我从用户处获取图像,并将其传递给tensorflow,以确定其中的内容: @app.route('/uploader', methods = ['GET', 'POST']) def upload_file(): if request.method == 'POST': f = request.files['file'] f.save(f.filename) i = Image.open(f) image_handler(i) def image_handler

我从用户处获取图像,并将其传递给tensorflow,以确定其中的内容:

 @app.route('/uploader', methods = ['GET', 'POST'])
 def upload_file():
  if request.method == 'POST':
   f = request.files['file']
   f.save(f.filename)
   i = Image.open(f)
   image_handler(i)

def image_handler(image):
 create_graph()
 print("Model loaded")

node_lookup = NodeLookup()
print("Node lookup loaded")

print("Img: ")
print(image)
predictions = dict(run_inference_on_image(image))
print(predictions)
return jsonify(predictions=predictions)
image_handler()正在使用tensorflow imagenet repo中的函数和NodeLookup类,可在此处找到:

问题是,当我运行应用程序时,它将加载良好,用户也可以选择图像良好,但当他们点击提交时,在获取预测时会出现以下错误:

Expected binary or unicode string, got <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=200x200 at 0x243126ABA90>
应为二进制或unicode字符串,已获取

看起来您正在使用image.open返回的PngImageFile对象调用run\u interference\u on\u image。但是在\u映像上运行\u推断\u需要一个文件名。看起来您正在使用image.open返回的PngImageFile对象调用在\u映像上运行\u推断\u。但在图像上运行图像需要一个文件名。