Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import tensorflow as tf
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. data_path = 'train.tfrecords' # address to save the hdf5 file
  5. with tf.Session() as sess:
  6. feature = {'train/image': tf.FixedLenFeature([], tf.string),
  7. 'train/label': tf.FixedLenFeature([], tf.int64)}
  8. # Create a list of filenames and pass it to a queue
  9. filename_queue = tf.train.string_input_producer([data_path], num_epochs=1)
  10. # Define a reader and read the next record
  11. reader = tf.TFRecordReader()
  12. _, serialized_example = reader.read(filename_queue)
  13. # Decode the record read by the reader
  14. features = tf.parse_single_example(serialized_example, features=feature)
  15. # Convert the image data from string back to the numbers
  16. image = tf.decode_raw(features['train/image'], tf.float32)
  17.  
  18. # Cast label data into int32
  19. label = tf.cast(features['train/label'], tf.int32)
  20. # Reshape image data into the original shape
  21. image = tf.reshape(image, [224, 224, 3])
  22.  
  23. # Any preprocessing here ...
  24.  
  25. # Creates batches by randomly shuffling tensors
  26. images, labels = tf.train.shuffle_batch([image, label], batch_size=10, capacity=30, num_threads=1, min_after_dequeue=10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement