Last active
November 8, 2018 10:08
-
-
Save hyzhak/86101fc3c4a0aa75dd8e89283c9521fb to your computer and use it in GitHub Desktop.
Convert tensorflow dataset to pandas dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import tensorflow as tf | |
def convert_tf_to_pd(ds, limit=32): | |
""" | |
Read data from Tensorflow dataset to Pandas dataframe | |
:param ds: | |
:param limit: | |
:return: | |
""" | |
batch_iterator = ds.batch(limit).make_one_shot_iterator() | |
with tf.Session() as sess: | |
batch = batch_iterator.get_next() | |
features_and_labels = sess.run(batch) | |
samples = { | |
**features_and_labels[0], | |
'label': features_and_labels[1], | |
} | |
return pd.DataFrame.from_dict(samples) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment