Guest User

Untitled

a guest
Oct 21st, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import tensorflow as tf
  2. import matplotlib.image as mpimg
  3. import numpy as np
  4.  
  5. IMAGE_SIZE = 224
  6.  
  7. def tf_resize_images(X_img_file_paths):
  8. X_data = []
  9. tf.reset_default_graph()
  10. X = tf.placeholder(tf.float32, (None, None, 3))
  11. tf_img = tf.image.resize_images(X, (IMAGE_SIZE, IMAGE_SIZE),
  12. tf.image.ResizeMethod.NEAREST_NEIGHBOR)
  13. with tf.Session() as sess:
  14. sess.run(tf.global_variables_initializer())
  15.  
  16. # Each image is resized individually as different image may be of different size.
  17. for index, file_path in enumerate(X_img_file_paths):
  18. img = mpimg.imread(file_path)[:, :, :3] # Do not read alpha channel.
  19. resized_img = sess.run(tf_img, feed_dict = {X: img})
  20. X_data.append(resized_img)
  21.  
  22. X_data = np.array(X_data, dtype = np.float32) # Convert to numpy
  23. return X_data
Add Comment
Please, Sign In to add comment