使用FastGFile图像数据进行Tensorflow服务

时间:2018-08-27 18:17:37

标签: tensorflow tensorflow-serving

我正在研究Tensorflow Serving example,它像这样在客户端中输入图像数据:

request.inputs['image'].CopyFrom(
        tf.contrib.util.make_tensor_proto(data, shape=[1]))

但是,这与我的导出模型不兼容,后者定义了如下输入张量:

input_tensor = 'DecodeJpeg/contents:0'
in_image = sess.graph.get_tensor_by_name(input_tensor)
inputs = {'image': tf.saved_model.utils.build_tensor_info(in_image)}

因此,当我运行客户端时,会出现此错误:

details = "contents must be scalar, got shape [1]    [[Node: DecodeJpeg
= DecodeJpeg[_output_shapes=[[?,?,3]], acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false,
_device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJpeg/contents_0_0)]]"    debug_error_string = "{"created":"@1535390769.933168011","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1095,"grpc_message":"contents must be scalar, got shape [1]\n\t [[Node: DecodeJpeg = DecodeJpeg[_output_shapes=[[?,?,3]], acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false,
_device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJpeg/contents_0_0)]]","grpc_status":3}"


我应该如何获取正确形状的输入图像数据?

这是我完整的export_model函数:

https://gist.github.com/iandow/14c82b4ab5d3ee8d3b5f4eb27b48ba6d

这是我的完整客户:

https://gist.github.com/iandow/0a39fe58784fdbb5d276d03b19ec4f02

从本质上讲,我正在尝试像在Tensorflow中所做的那样训练模型,以便诗人与Tensorflow服务一起使用。也许我正在解决所有这些错误,但是我认为如果我能以正确的形状获得输入图像数据,那么这将起作用。感谢您的帮助。

0 个答案:

没有答案