TensorFlow - 读取CSV格式文件
2017-09-14 16:30
387 查看
TensorFlow - 读取CSV格式文件
flyfish
以TensorFlow提供的例子说明
API说明concat
代码示例
tf.concat( [t1,t2],0)的结果是
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
tf.concat( [t1,t2],1)的结果是
[[ 1 2 3 7 8 9]
[ 4 5 6 10 11 12]]
API说明stack
代码示例
tf.stack([x, y, z],0)的结果是
[[1 2]
[3 4]
[5 6]]
tf.stack([x, y, z],1)的结果是
[[1 3 5]
[2 4 6]]
To read text files in comma-separated value (CSV) format, use a
tf.TextLineReader with the tf.decode_csv operation.
读取CSV格式的文本文件, 需要使用TextLineReader和decode_csv 操作
Each execution of read reads a single line from the file. The
decode_csv op then parses the result into a list of tensors. The
record_defaults argument determines the type of the resulting >tensors and sets thedefault value to use if a value is missing in the >input string.
每次执行read都会从文件中读取一行内容, decode_csv 操作会将内容解析到张量列表。record_default参数决定了结果的张量的类型,并设置了如果在输入字符串中缺失值时的默认值。
You must call tf.train.start_queue_runners to populate the queue
before you call run or eval to execute the read. Otherwise read will
block while it waits for filenames from the queue.
你必须在调用run或者eval去执行read之前, 调用tf.train.start_queue_runners来填充队列。否则read操作会阻塞。
flyfish
以TensorFlow提供的例子说明
filename_queue = tf.train.string_input_producer(["file0.csv", "file1.csv"]) reader = tf.TextLineReader() key, value = reader.read(filename_queue) # Default values, in case of empty columns. Also specifies the type of the # decoded result. record_defaults = [[1], [1], [1], [1], [1]] col1, col2, col3, col4, col5 = tf.decode_csv( value, record_defaults=record_defaults) features = tf.stack([col1, col2, col3, col4]) with tf.Session() as sess: # Start populating the filename queue. coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) for i in range(1200): # Retrieve a single instance: example, label = sess.run([features, col5]) coord.request_stop() coord.join(threads)
API说明concat
代码示例
import tensorflow as tf t1 = [[1, 2, 3],[4, 5, 6]] t2 = [[7, 8, 9],[10, 11, 12]] result =(tf.concat( [t1,t2],0)) sess = tf.Session() print(sess.run(result))
tf.concat( [t1,t2],0)的结果是
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
tf.concat( [t1,t2],1)的结果是
[[ 1 2 3 7 8 9]
[ 4 5 6 10 11 12]]
API说明stack
代码示例
import tensorflow as tf x =[1, 2] y= [3, 4] z= [5, 6] result =tf.stack([x, y, z],0) sess = tf.Session() print(sess.run(result))
tf.stack([x, y, z],0)的结果是
[[1 2]
[3 4]
[5 6]]
tf.stack([x, y, z],1)的结果是
[[1 3 5]
[2 4 6]]
To read text files in comma-separated value (CSV) format, use a
tf.TextLineReader with the tf.decode_csv operation.
读取CSV格式的文本文件, 需要使用TextLineReader和decode_csv 操作
Each execution of read reads a single line from the file. The
decode_csv op then parses the result into a list of tensors. The
record_defaults argument determines the type of the resulting >tensors and sets thedefault value to use if a value is missing in the >input string.
每次执行read都会从文件中读取一行内容, decode_csv 操作会将内容解析到张量列表。record_default参数决定了结果的张量的类型,并设置了如果在输入字符串中缺失值时的默认值。
You must call tf.train.start_queue_runners to populate the queue
before you call run or eval to execute the read. Otherwise read will
block while it waits for filenames from the queue.
你必须在调用run或者eval去执行read之前, 调用tf.train.start_queue_runners来填充队列。否则read操作会阻塞。
相关文章推荐
- ORACLE读取CSV文件时对CSV格式的要求
- tensorflow读取数据之CSV格式
- R读取txt、csv、xls和xlsx格式文件
- MT4函数_读取CSV格式文件存入到二维数组
- c#读取csv文件成DataTable,将DataTable数据存储为csv格式文件
- java读取导入csv格式 文件
- php读取csv文件(excel可另存为csv格式文件)
- spark2.x读取csv格式文件
- 读取csv文件转换成你自己想要格式的数据
- C#读取csv格式文件
- tensorflow读取数据之CSV格式
- SparkR读取CSV格式文件错误java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.spark.u
- 内容写到 csv 格式的文件中 及 读取 csv 格式的文件内容
- 通过读取文件头部判断是否为CSV格式文件
- Tensorflow学习笔记之用TF读取csv文件的限制
- csv格式文件读取
- python.matplotlib/datatime/CSV学习范例-读取CSV格式文件生成折线图
- 读取五种格式的配置文件(xml(两种方式),txt,excel,csv,json)
- vba中读取utf-8格式的csv文件保证不乱码
- python读取与写入csv格式文件的示例代码