如何在张量流中使用tf.string_split()?

时间:2016-10-20 06:07:44

标签: tensorflow

我想得到图像文件的扩展来调用不同的图像解码器,我发现在tensorflow r0.11中有一个名为tf.string_split的函数。

filename_queue = tf.train.string_input_producer(filenames, shuffle=shuffle)
reader = tf.WholeFileReader()
img_src, img_bytes = reader.read(filename_queue)
split_result = tf.string_split(img_src, '.')

但是当我运行它时,我收到了这个错误:

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

我认为这可能是由img_src的形状推断引起的。我尝试使用img_src.set_shape([1,])来修复它,但似乎无效,我收到此错误:

ValueError: Shapes () and (1,) are not compatible

另外,我无法使用

获得img_src的形状
tf.Print(split_result, [tf.shape(img_src)],'img_src shape=')

结果是img_src shape=[]。但是,如果我使用以下代码:

tf.Print(split_result, [img_src],'img_src=')

结果是img_src=test_img/test1.png。我做错了吗?

1 个答案:

答案 0 :(得分:8)

img_src打包成张量。

split_result = tf.string_split([img_src], '.')
相关问题