Skip to main content

A Tensorflow MongoDB connector

Project description

TFMongoDB is a C++ implemented dataset op for google’s tensorflow that allows you to connect to your MongoDatabase natively. Hence you can access your mongodb stored documents more efficiently.

Currently only MacOS X is supported while Tensorflow >= 1.5 is required.


Installation

In order to use the dataset you need to install it with pip:

pip install tfmongodb

Usage

TFMongoDB can be accessed through the MongoDBDataset:

dataset = MongoDBDataset(<database_name>, <collection_name>)

example:

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))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for TFMongoDB, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size TFMongoDB-0.1.3-cp37-cp37m-macosx_10_14_x86_64.whl (73.5 kB) File type Wheel Python version cp37 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page