我正在尝试将数据从 CSV 文件读取到张量流,
https://www.tensorflow.org/versions/r0.7/how_tos/reading_data/index.html#filenames-shuffling-and-epoch-limits https://www.tensorflow.org/versions/r0.7/how_tos/reading_data/index.html#filenames-shuffling-and-epoch-limits
官方文档中的示例代码是这样的:
col1, col2, col3, col4, col5 = tf.decode_csv(value, record_defaults=record_defaults)
要读取文件,我需要事先知道文件中有多少列和行,如果有 1000 列,我需要定义 1000 个变量,例如col1, col2, col3, col4, col5,..., col1000 ,
这看起来不像是读取数据的有效方法。
我的问题
将 CSV 文件读入 Tensorflow 的最佳方法是什么?
有没有办法读取Tensorflow中的数据库(例如mongoDB)?
-
你绝对不需要定义 col1、col2、到 col1000...
一般来说,你可能会这样做:
columns = tf.decode_csv(value, record_defaults=record_defaults)
features = tf.pack(columns)
do_whatever_you_want_to_play_with_features(features)
我不知道有什么现成的方法可以直接从 MongoDB 读取数据。也许你可以编写一个简短的脚本来将 MongoDB 中的数据转换为 Tensorflow 支持的格式,我建议二进制形式TFRecord
,读取速度比 csv 记录快得多。This https://indico.io/blog/tensorflow-data-inputs-part1-placeholders-protobufs-queues/是一篇关于这个主题的很好的博客文章。或者您可以选择自己实现定制的数据读取器,请参阅官方文档 https://www.tensorflow.org/versions/r0.7/how_tos/new_data_formats/index.html#custom-data-readers here.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)