Skip to content

Instantly share code, notes, and snippets.

@girija2204
Created July 23, 2020 03:27
Show Gist options
  • Save girija2204/2098bef518be1b115d30d30ce0bc104a to your computer and use it in GitHub Desktop.
Save girija2204/2098bef518be1b115d30d30ce0bc104a to your computer and use it in GitHub Desktop.
train_tensor_slices = tf.data.Dataset.from_tensor_slices((x_train,y_train))
type(train_tensor_slices)
# tensorflow.python.data.ops.dataset_ops.TensorSliceDataset
image, label = next(iter(train_tensor_slices))
labels[label.numpy()[0]]
# ‘frog’
train_tensor_slices_list = list(iter(train_tensor_slices))
# checking if the element fetched with next on the iterator and the first element of the list are the same or not
tf.reduce_all(tf.math.equal(next(iter(train_tensor_slices))[0], train_tensor_slices_list[0][0])).numpy() # image
# True
tf.reduce_all(tf.math.equal(next(iter(train_tensor_slices))[1], train_tensor_slices_list[0][1])).numpy() # label
# True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment