将PIL PngImageFile传递给张量流以进行图像识别

时间:2017-11-21 14:42:56

标签: 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(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类: https://github.com/tensorflow/models/blob/master/tutorials/image/imagenet/classify_image.py

问题是,当我运行应用程序时,它会加载正常,用户也可以选择一个图像,但是当他们点击提交时,它会在获得预测时收到以下错误:

Expected binary or unicode string, got <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=200x200 at 0x243126ABA90>

0 个答案:

没有答案