Advertisement
Guest User

Untitled

a guest
Sep 7th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import tensorflow as tf
  2. import os
  3.  
  4. def parse_fn(example):
  5.     example_fmt = {
  6.             'image/encoded': tf.FixedLenFeature((), tf.string, ""),
  7.             'image/format': tf.FixedLenFeature((), tf.string, ""),
  8.             'image/class/label': tf.FixedLenFeature((), tf.int64, -1),
  9.             'image/height': tf.FixedLenFeature((), tf.int64, -1),
  10.             'image/width': tf.FixedLenFeature((), tf.int64, -1)
  11.     }
  12.     parsed = tf.parse_single_example(example, example_fmt)
  13.     image = tf.image.decode_image(parsed['image/encoded'])
  14.     label = parsed['image/class/label']
  15.     return image, label
  16.  
  17. files = tf.data.Dataset.list_files(os.path.join(".\\datasets\\cifar-10-2\\train.tfrecords"))
  18. dataset = files.interleave(tf.data.TFRecordDataset, 1) # cycle_length = num files
  19. dataset = dataset.apply(tf.contrib.data.map_and_batch(map_func=parse_fn, batch_size=128, drop_remainder=True))
  20. dataset = dataset.apply(tf.contrib.data.shuffle_and_repeat(buffer_size=128, count=None))
  21. dataset = dataset.prefetch(buffer_size=1)
  22. itr = dataset.make_one_shot_iterator().get_next()
  23.  
  24. print(itr)
  25. with tf.Session('') as s:
  26.     for el in itr:
  27.         print(s.run(el))
  28.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement