Skip to content

Instantly share code, notes, and snippets.

@hadifar
Last active September 15, 2018 15:06
Show Gist options
  • Select an option

  • Save hadifar/1467bfcb0a578abdc8b6c6aa5bd34efe to your computer and use it in GitHub Desktop.

Select an option

Save hadifar/1467bfcb0a578abdc8b6c6aa5bd34efe to your computer and use it in GitHub Desktop.
# create training Dataset and batch it
train_data = tf.data.Dataset.from_tensor_slices(train)
train_data = train_data.shuffle(10000) # if you want to shuffle your data
train_data = train_data.batch(128)
# create testing Dataset and batch it
test_data = tf.data.Dataset.from_tensor_slices(test)
test_data = test_data.shuffle(10000)
test_data = test_data.batch(128)
# create one iterator and initialize it with different datasets
iterator = tf.data.Iterator.from_structure(train_data.output_types,
train_data.output_shapes)
X, Y = iterator.get_next()
train_init = iterator.make_initializer(train_data) # initializer for train_data
test_init = iterator.make_initializer(test_data) # initializer for train_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment