读取textfile在tensorflow中返回空变量

时间:2017-03-02 07:48:18

标签: text tensorflow readfile

我有一个包含110行和1024列浮点值的文本文件。我试图加载文本文件,它没有读任何东西。

error(s)_during_the_evaluation

打印变量的形状返回filename = '300_faults.txt' filename_queue = tf.train.string_input_producer([filename]) reader = tf.TextLineReader() _,a = reader.read(filename_queue) #x = np.loadtxt('300_faults.txt') # working #a = tf.constant(x,tf.float32) # working model = tf.initialize_all_variables() with tf.Session() as session: session.run(model) print(session.run(tf.shape(a)))

1 个答案:

答案 0 :(得分:0)

首先 - tf.shape(a) == []并不意味着变量是空的。所有标量和字符串都具有形状[]

https://www.tensorflow.org/programmers_guide/dims_types

可能你可以检查“排名” - 对于标量和字符串它将是0。 除此之外,看起来string_input_producer是一个队列,需要额外的布线才能使其工作。

请试试这个

filename = '300_faults.txt'
filename_queue = tf.train.string_input_producer([filename])
reader = tf.TextLineReader()
_,a = reader.read(filename_queue)
#x = np.loadtxt('300_faults.txt')  # working
#a = tf.constant(x,tf.float32)     # working

model = tf.initialize_all_variables()
with tf.Session() as session:
    session.run(model)

    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)

    print(session.run(tf.shape(a)))

    print(session.run((a)))
    coord.request_stop()
    coord.join(threads)
相关问题