无法将类型为<class'werkzeug.datastructures.file.storage =“”>的对象转换为张量

时间:2018-04-01 10:06:05

标签: python tensorflow machine-learning tensorflow-serving werkzeug

我正在编写一个客户端python文件,它使用flask框架并在docker机器中运行它。所以这需要一个输入文件并生成它的输出。 但它抛出错误,它无法转换为张量。

tf.app.flags.DEFINE_string('server', 'localhost:9000', 'PredictionService host:port')
FLAGS = tf.app.flags.FLAGS

app = Flask(__name__)

class mainSessRunning():

    def __init__(self):
        host, port = FLAGS.server.split(':')
        channel = implementations.insecure_channel(host, int(port))
        self.stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

        self.request = predict_pb2.PredictRequest()
        self.request.model_spec.name = 'modelX'
        self.request.model_spec.signature_name = 'prediction'

    def inference(self, val_x):
        data = val_x
        self.request.inputs['input'].CopyFrom(tf.contrib.util.make_tensor_proto(data))
        result = self.stub.Predict(self.request, 5.0)
        return result

run = mainSessRunning()


# Define a route for the default URL, which loads the form
@app.route('/pred', methods=['POST'])
def pred():
    request_data = request.files['file']
    result = run.inference(request_data)
    rs = json_format.MessageToJson(result)
    return jsonify({'result':rs})

错误说:

  

TypeError:无法转换类型的对象   (class'werkzeug.datastructures.File.Storage')张量。内容:   (Filestorage:u'File.txt'('text / plain'))。考虑铸造元素   到支持的类型

此行产生错误:

  

self.request.inputs [ '输入']。具有copyfrom(tf.contrib.util.make_tensor_proto(数据))

pic

0 个答案:

没有答案