TensorFlow MongoDB连接器
TFMongoDB的Python项目详细描述
TFMOGODB是一个C++实现的数据集OP,用于谷歌的TysOracle流,允许您使用 以本机方式连接到您的Mongodatabase。因此您可以访问您存储的MongoDB 文件更有效。
当前仅支持MacOS X,而TensorFlow>;=1.5是必需的。
安装
为了使用数据集,您需要将其与pip一起安装:
pip install tfmongodb
用法
可以通过mongodbdataset访问tfmongodb:
dataset = MongoDBDataset(<database_name>, <collection_name>)
示例:
from tfmongodb import MongoDBDataset from tensorflow.python.framework import ops from tensorflow.python.data.ops import iterator_ops import tensorflow as tf CSV_TYPES = [[""], [""], [0]] def _parse_line(line): fields = tf.decode_csv(line, record_defaults=CSV_TYPES) return fields dataset = MongoDBDataset("eccounting", "creditors") dataset = dataset.map(_parse_line) repeat_dataset2 = dataset.repeat() batch_dataset = repeat_dataset2.batch(20) iterator = iterator_ops.Iterator.from_structure(batch_dataset.output_types) #init_op = iterator.make_initializer(dataset) init_batch_op = iterator.make_initializer(batch_dataset) get_next = iterator.get_next() with tf.Session() as sess: # Basic test: read from topic 0. sess.run(init_batch_op, feed_dict={}) for i in range(5): print(sess.run(get_next))