Created
February 5, 2018 01:06
-
-
Save dineshj1/1c07801f88a04d2ff48a1b2bc3808c2b to your computer and use it in GitHub Desktop.
Script to explore tensorflow records file
This file contains hidden or 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
# Written with help from http://warmspringwinds.github.io/tensorflow/tf-slim | |
# /2016/12/21/tfrecords-guide/ | |
import os | |
import ipdb | |
import numpy as np | |
import tensorflow as tf | |
from tqdm import tqdm | |
tf_dir = './' | |
fn_list = ['train_000.tf'] | |
feats = { | |
'label' : tf.FixedLenFeature([], dtype=tf.int64), | |
'action': tf.FixedLenFeature([5], dtype=tf.float32) | |
} | |
for fn in fn_list: | |
full_fn = os.path.join(tf_dir, fn) | |
num_egs = sum(1 for _ in tf.python_io.tf_record_iterator(full_fn)) | |
print("Reading %d examples" % num_egs) | |
action = np.zeros((num_egs, 5), dtype='float32') | |
label = np.zeros(num_egs, dtype='int64') | |
for ct, record in enumerate(tqdm( | |
tf.python_io.tf_record_iterator(full_fn))): | |
example = tf.train.Example.FromString(record) | |
if ct == 0: | |
fieldnames = sorted(example.features.feature.keys()) | |
print(fieldnames) | |
started = True | |
assert ('label' in fieldnames) | |
assert ('action' in fieldnames) | |
label[ct] = np.array(example.features.feature['label'].int64_list.value) | |
action[ct] = np.array(example.features.feature['action'].float_list.value[:]) | |
ipdb.set_trace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment