生活随笔
收集整理的這篇文章主要介紹了
[tensorflow] - csv文件读取
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
-
參考
-
文件流程
-
csv讀取流程
-
函數(shù)的流程
import tensorflow
as tf
import os
"""tensorflow中csv文件的讀取1、 先找到文件,構(gòu)造一個列表2、 構(gòu)造一個文件隊列3、 讀取(read)隊列內(nèi)容csv: 讀取一行二進制文件: 指定一個樣本的bytes讀取圖片文件: 按一張一張的讀取4、 解碼(decode)tf.decode_csv(records, record_defaults=None,field_delim = None, name=None)5、 批處理(多個樣本)批處理大小,和數(shù)量無關(guān).取決于該批次處理數(shù)量的大小
"""def csvread(filelist
):"""讀取CSV文件:param filelist: 文件路徑 + 名字列表:return: 讀取的內(nèi)容"""file_queue
= tf
.train
.string_input_producer
(filelist
)reader
= tf
.TextLineReader
()key
, value
= reader
.read
(file_queue
)records
= [["None"], ["None"]]example
, label
= tf
.decode_csv
(value
, record_defaults
=records
)example_batch
, label_batch
= tf
.train
.batch
([example
, label
], batch_size
=9, num_threads
=1, capacity
=9)print(example_batch
, label_batch
)return example_batch
, label_batch
if __name__
== "__main__":file_name
= os
.listdir
("./data/csvdata/")filelist
= [os
.path
.join
("./data/csvdata", file) for file in file_name
]example_batch
, label_batch
= csvread
(filelist
)with tf
.Session
() as sess
:coord
= tf
.train
.Coordinator
()threads
= tf
.train
.start_queue_runners
(sess
, coord
=coord
)print(sess
.run
([example_batch
, label_batch
]))filewriter
= tf
.summary
.FileWriter
("./summary/", graph
=sess
.graph
)coord
.request_stop
()coord
.join
(threads
)
總結(jié)
以上是生活随笔為你收集整理的[tensorflow] - csv文件读取的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。