Python Tensorflow启动与图像上传

Python Tensorflow启动与图像上传,python,flask,tensorflow,Python,Flask,Tensorflow,我正试图使用一个烧瓶包装器将一个图像上传到TF Inception模型中,但这是我在通过postman进行测试时遇到的错误。我已经尝试了很多谷歌搜索/SO,但没有找到一种方法来解决最初使用的图像数据部分 image_data = tf.gfile.FastGFile(image_path, 'rb').read() 但我已经将其更改为使用flask的请求模块来接受图像数据,而这一直都是空的 image_data = request.data 但是我想传递我上传的图像文件的数据 错误: Inv

我正试图使用一个烧瓶包装器将一个图像上传到TF Inception模型中,但这是我在通过postman进行测试时遇到的错误。我已经尝试了很多谷歌搜索/SO,但没有找到一种方法来解决最初使用的图像数据部分

image_data = tf.gfile.FastGFile(image_path, 'rb').read()
但我已经将其更改为使用flask的请求模块来接受图像数据,而这一直都是空的

image_data = request.data
但是我想传递我上传的图像文件的数据

错误:

InvalidArgumentError (see above for traceback): Invalid JPEG data, size 0
     [[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)]]
代码:

完全重写答案,感谢您的澄清

所以,我的理解是,当您直接使用文件名时,您的代码工作得很好,但一旦您尝试从文章中读取文件,代码就会失败

在代码中,检索文件的方式如下:

image_data = request.data
我发现您可能应该像这样获取数据:

# check if the post request has the file part
if 'file' not in request.files:
    flash('No file part')
    return redirect(request.url)
file = request.files['file']

我正在上载该文件及其错误所在的位置。如果您阅读了“代码”部分,您就会知道。@user6083088如果这回答了您的问题,请将其标记为首选答案
# check if the post request has the file part
if 'file' not in request.files:
    flash('No file part')
    return redirect(request.url)
file = request.files['file']