如何在tensorflow中使用tf.string_split()?

Oti*_*ong 7 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, '.')
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,我收到此错误:

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

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

ValueError: Shapes () and (1,) are not compatible
Run Code Online (Sandbox Code Playgroud)

而且,我无法获得img_src使用的形状

tf.Print(split_result, [tf.shape(img_src)],'img_src shape=')
Run Code Online (Sandbox Code Playgroud)

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

tf.Print(split_result, [img_src],'img_src=')
Run Code Online (Sandbox Code Playgroud)

结果是img_src=test_img/test1.png.难道我做错了什么?

nes*_*uno 8

只需img_src填入张量.

split_result = tf.string_split([img_src], '.')
Run Code Online (Sandbox Code Playgroud)