Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import tensorflow as tf
  2. import numpy as np
  3. from scipy.misc import imread, imresize
  4.  
  5. def preProcess(image):
  6. image = imresize(image, (224,224))
  7. mean = [123.68, 116.779, 103.939]
  8. images = image-mean
  9. return images
  10.  
  11. img1 = imread('laska.png', mode = 'RGB')
  12. data = preProcess(img1)
  13. with open('input.txt', 'w') as outfile:
  14. # I'm writing a header here just for the sake of readability
  15. # Any line starting with "#" will be ignored by numpy.loadtxt
  16. #outfile.write('# Array shape: {0}\n'.format(data.shape))
  17. data_split = np.split(data, 3, axis = 2)
  18. outfile.write('%d %d %d' % (data.shape[0], data.shape[1], data.shape[2]))
  19. outfile.write('\n')
  20. for i in range(data.shape[2]):
  21. np.savetxt(outfile, data[...,i], fmt='%-15.7f')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement