读取文本文件在tensorflow中返回空变量
reading textfile returning empty variable in tensorflow
我有一个包含 110 行和 1024 列浮点值的文本文件。我正在尝试加载文本文件,但它没有读取任何内容。
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)))
打印变量的形状 returns []
。
首先 - tf.shape(a) == []
并不意味着变量为空。所有标量和字符串的形状都是 []
。
https://www.tensorflow.org/programmers_guide/dims_types
也许您可以改为检查 "rank" - 对于标量和字符串,它将为 0。
除此之外,它看起来像 string_input_producer
是一个队列,它需要额外的布线才能使 ti 工作。
请试试这个
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)
我有一个包含 110 行和 1024 列浮点值的文本文件。我正在尝试加载文本文件,但它没有读取任何内容。
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)))
打印变量的形状 returns []
。
首先 - tf.shape(a) == []
并不意味着变量为空。所有标量和字符串的形状都是 []
。
https://www.tensorflow.org/programmers_guide/dims_types
也许您可以改为检查 "rank" - 对于标量和字符串,它将为 0。
除此之外,它看起来像 string_input_producer
是一个队列,它需要额外的布线才能使 ti 工作。
请试试这个
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)