如何使用tf.decode_csv在tensorflow中解码长行的csv文件? [英] How to decode a csv file with long lines in tensorflow with tf.decode_csv?

查看:63
本文介绍了如何使用tf.decode_csv在tensorflow中解码长行的csv文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用tf.TextLineReader()和tf.decode_csv对行较长的 csv 文件进行解码(例如,每行包含很多项,以至于不现实地将它们逐一列出以进行输出)?

How to decode a csv file with long lines(e.g., with many items per line so as not realistic to list them one by one for output) with tf.TextLineReader() and tf.decode_csv?

典型用法是:

reader = tf.TextLineReader()    
key, value = reader.read(filename_queue)    
record_defaults = [1,1,1,1,1]    
a,b,c,d,e =  tf.decode_csv(records=value,record_defaults=record_defaults, field_delim=" ")

当一行中有成千上万个项目时,不可能像上面的(a,b,c,d,e)一样逐一分配它们,是否可以将所有项目解码为列表或类似内容?

When we have thousands of items in a line, it's impossible to assign them one by one as (a,b,c,d,e) above, can all the items be decoded to a list or something like that?

推荐答案

假设您有1800列数据.您可以将其用作记录默认值:

Lets say you have 1800 columns of data. You can use this as record default:

record_defaults=[[1]]*1800

然后使用

all_columns = tf.decode_csv(value, record_defaults=record_defaults)

阅读它们.

这篇关于如何使用tf.decode_csv在tensorflow中解码长行的csv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆