Guest User

Untitled

a guest
Oct 11th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import tensorflow as tf
  2. import tensorflow_datasets as tfds
  3.  
  4. # tfds works with Eager and Graph modes
  5. tf.enable_eager_execution()
  6.  
  7. # 0. Select the dataset you'd like to use
  8. print(tfds.list_builders())
  9.  
  10. # 1. Construct the DatasetBuilder
  11. # Each dataset is implemented as a DatasetBuilder and can be fetched by
  12. # string name.
  13. mnist_builder = tfds.builder(name="mnist", data_dir="~/tfds/data")
  14.  
  15. # 2. Download and prepare the dataset into a format ready for a tf.data pipeline
  16. mnist_builder.download_and_prepare()
  17.  
  18. # 3. Build a tf.data.Dataset from the prepared data
  19. train_dataset = mnist_builder.as_dataset(split=tfds.Split.TRAIN)
  20.  
  21. # 4. Build the rest of your input pipeline using the tf.data API
  22. train_dataset = train_dataset.repeat().shuffle(1024).batch(32).prefetch(100)
  23.  
  24. # If we looked at a single batch, it has a features dictionary with keys
  25. # "input" and "target"
  26. features, = train_dataset.take(1)
  27. images, labels = features["input"], features["target"]
Add Comment
Please, Sign In to add comment