当前位置:网站首页>Tensorflow中CSV文件数据读取
Tensorflow中CSV文件数据读取
2022-06-25 22:08:00 【smileapples】
Tensorflow中CSV文件数据读取主要步骤:
1、找到文件 构造文件列表
2、构建一个文件队列
3、构建文件阅读器 读取队列内容(一行)
4、文件解码
5、批处理读取大量数据
代码实现如下:
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = "2"
tf = tf.compat.v1
def read_csvfile(filelist):
''' 读取CSV文件 :param file_list:文件名列表 :return: '''
# 1构造文件队列
filequeue = tf.train.string_input_producer(filelist)
# 2构造csv阅读器读取
reader = tf.TextLineReader()
key,value = reader.read(filequeue)
# print(key,value)
# 3解码文件
records = [["None"],["None"]]
example,label = tf.decode_csv(value,record_defaults=records) #record_defaults指定每一个样本每一列的类型
# print(example,label)
# 4批处理读取多个数据
example_batch, label_batch = tf.train.batch([example, label], batch_size=10, num_threads=2, capacity=9)
# print(example_batch, label_batch)
return example_batch,label_batch
if __name__ == "__main__":
# 0获取文件 构建文件列表
# 获取文件名
filenames = os.listdir("../data/csvdata/")
# print(filenames)
#拼接路径形成完整文件名称
filelist = [os.path.join("../data/csvdata",filename) for filename in filenames]
# print(filelist)
example_batch,label_batch = read_csvfile(filelist)
# 开启会话,运行结果
with tf.Session() as sess:
# 定义一个线程协调器
coord = tf.train.Coordinator()
# 开启读取文件的线程
filereadthreads = tf.train.start_queue_runners(sess,coord=coord)
# 输出读取的内容
print(sess.run([example_batch,label_batch]))
# 回收子线程
coord.request_stop()
coord.join(filereadthreads)
边栏推荐
- Wireshark对IMAP抓包分析
- 登录拦截器
- Analysis on the control condition and mode of go cooperation overtime exit
- Mutual conversion between QT utf8 and Unicode encoding, and the Unicode encoding output format is &xxxxx
- final和static
- A. Balance the Bits--Codeforces Round #712 (Div. 1)
- Format the number. If the number is not enough, fill in 0, for example, 1:0001,25:0025
- 流数据
- Hibernate entity class curd, transaction operation summary
- C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
猜你喜欢

One article explains R & D efficiency! Your concerns are

Bi-sql stored procedure (I)

Visual studio code create minimal web API (asp.net core)

先序线索二叉树

How does excel translate Chinese words into English automatically? This formula teaches you

Line height for small use
![mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动](/img/b2/2b87b3cea1422e2a860f5e0e7dcc40.png)
mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动

Kotlin空指针Bug

The simplest screen recording to GIF gadget in history, licecap, can be tried if the requirements are not high

CSDN add on page Jump and off page specified paragraph jump
随机推荐
谈一谈生产环境中swoole协程创建数量控制机制
Today's 61 Fu
C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
DPVS-FullNAT模式管理篇
idea Kotlin版本升级
Hibernate entity class curd, transaction operation summary
The InputStream stream has been closed, but the file or folder cannot be deleted, indicating that it is occupied by the JVM
php中使用google protobuf协议环境配置
c_ uart_ interface_ Example and offboard modes
MySQL自定义函数实例
Architecture part -- the use of UMI framework and DVA
Screen recording to GIF is an easy-to-use gadget, screentogif, which is free and easy to use!
final和static
How does excel translate Chinese words into English automatically? This formula teaches you
森林的先序和中序遍历
Uni app -- listen for the exit of the return key
Analysis on the control condition and mode of go cooperation overtime exit
DPVS-FullNAT模式部署篇
InputStream流已经关闭了,但是依旧无法delete文件或者文件夹,提示被JVM占用等
excel如何实现中文单词自动翻译成英文?这个公式教你了