Skip to content

Instantly share code, notes, and snippets.

@mrajchl
Last active October 6, 2019 11:57
Show Gist options
  • Save mrajchl/d2a9afcbbd361fab4cbd4beb557781a0 to your computer and use it in GitHub Desktop.
Save mrajchl/d2a9afcbbd361fab4cbd4beb557781a0 to your computer and use it in GitHub Desktop.
Load a tf feed_dict with data from memory
# Load all data into memory
data = load_data(all_filenames, tf.estimator.ModeKeys.TRAIN, reader_params)
# Create placeholder variables and define their shapes (here,
# we input a volume image of size [128, 224, 244] and a single
# channel (i.e. greyscale):
x = tf.placeholder(reader_example_dtypes['features']['x'],
[None, 128, 224, 224, 1])
y = tf.placeholder(reader_example_dtypes['labels']['y'],
[None, 1])
# Create a tf.data.Dataset
dataset = tf.data.Dataset.from_tensor_slices((x, y))
dataset = dataset.repeat(None)
dataset = dataset.batch(batch_size)
dataset = dataset.prefetch(1)
# Create an iterator
iterator = dataset.make_initializable_iterator()
nx = iterator.get_next()
with tf.train.MonitoredTrainingSession() as sess_dict:
sess_dict.run(iterator.initializer,
feed_dict={x: data['features'], y: data['labels']})
for i in range(iterations):
# Get next features/labels pair
dict_batch_feat, dict_batch_lbl = sess_dict.run(nx)
@Aliktk
Copy link

Aliktk commented Oct 6, 2019

I am facing below problem when i am running your code>? why is load_data is not defined in your program

load_data(all_filenames, tf.estimator.ModeKeys.TRAIN, reader_params)

NameError: name 'Loaddata' is not defined

@mrajchl
Copy link
Author

mrajchl commented Oct 6, 2019

Because this is a gist code snippet, not a stand alone script. I'd refer to the actual tutorial: https://github.com/DLTK/DLTK/blob/master/examples/tutorials/01_reading_medical_images_in_tf.ipynb

@Aliktk
Copy link

Aliktk commented Oct 6, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment