我是TensorFow的新手,但我必须使用它,所以我有一个问题.
我必须在csv文件中使用特定数据,如下所示:
0.5,1,0,0,Slow_Start
1,2,0,0,Slow_Start
1.5,4,0,0,Slow_Start
2,8,0,0,Slow_Start
(Slow_Start是我必须使用的标签之一).
我使用以下代码成功导入了我的数据
directory = "/home/matthieu/Documents/python/*.csv"
filename_queue = tf.train.string_input_producer(
tf.train.match_filenames_once(directory),
shuffle=False)
line_reader = tf.TextLineReader()
_, csv_row = line_reader.read(filename_queue)
record_defaults = [[0.0], [0.0], [0.0], [0.0], [""]]
time, cwnd, rtt, dupack, Algo = \
tf.decode_csv(csv_row, record_defaults=record_defaults)
features = tf.pack([
time,
cwnd,
rtt,
dupack])
with tf.Session() as sess:
tf.initialize_all_variables().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
# we grab an example from the CSV file.
for iteration in range(1, 50):
example, label = sess.run([features, Algo])
print(example, label)
coord.request_stop()
coord.join(threads) …Run Code Online (Sandbox Code Playgroud)