Failed to convert object of type <class 'werkzeug.datastructures.File.Storage> to tensor

ぐ巨炮叔叔 提交于 2019-12-10 15:14:45

问题


I am writing a client python file that uses flask framework and running this inside a docker machine. So this take an input file and produces output of it. But it throws error that it cant convert to tensor.

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})

The error says:

TypeError: Failed to convert object of type (class'werkzeug.datastructures.File.Storage') to tensor. Contents: (Filestorage: u'File.txt' ('text/plain')). Consider casting elements to a supported type

This line produces the error:

self.request.inputs['input'].CopyFrom(tf.contrib.util.make_tensor_proto(data))

来源:https://stackoverflow.com/questions/49596937/failed-to-convert-object-of-type-class-werkzeug-datastructures-file-storage-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!