TensorFlow DecodePng抛出值错误

时间:2017-11-16 19:21:21

标签: tensorflow tensorflow-serving

对于解码png图像,通常我们使用以下代码段。

image_placeholder = tf.placeholder(tf.string)
image_tensor = tf.read_file(image_placeholder)
image_tensor = tf.image.decode_png(image_tensor, channels=1)

为了使用Tensorflow服务部署模型,我按照Inception_saved_model的示例为我自己的模型版本。下面是该程序中用于读取传入的tensorproto的代码。

image_placeholder = tf.placeholder(tf.string, name='images')

feature_configs = {'images': tf.FixedLenFeature(shape=[], dtype=tf.string), }
tf_example = tf.parse_example(image_placeholder, feature_configs)
image_tensor = tf_example['images']

image_tensor = tf.image.decode_png(image_tensor, channels=1)

当我使用此代码时,Decode_png会抛出Value错误:

ValueError: Shape must be rank 0 but is rank 1 for 'DecodePng' (op: 'DecodePng') with input shapes: [?].

有人可以帮助我解决我的错误吗?我在这里介绍的代码类似于Inception示例中给出的代码。

1 个答案:

答案 0 :(得分:1)

tf.parse_example在批处理上运行("排名1"),decode_png需要单个图像(标量字符串,"排名0")。在使用reshape之前,我要先使用tf.parse_single_example或将shape=[]添加到标量(decode_png)。