ashwinnair14

Untitled

Dec 14th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import h5py, os
  2. import caffe
  3. import numpy as np
  4.  
  5. SIZE = 224 # fixed size to all images
  6. with open( 'val1.txt', 'r' ) as T :
  7. lines = T.readlines()
  8. # If you do not have enough memory split data into
  9. # multiple batches and generate multiple separate h5 files
  10. X = np.zeros( (len(lines), 3, SIZE, SIZE), dtype='f4' )
  11. y = np.zeros( (len(lines),1), dtype='f4' )
  12. z = np.zeros( (len(lines),4), dtype='f4' )
  13. print y.shape
  14. for i,l in enumerate(lines):
  15. sp = l.split(' ')
  16. cls= int(sp[1][:-1])
  17. img = caffe.io.load_image( sp[0] )
  18. img = caffe.io.resize( img, (SIZE, SIZE, 3) ) # resize to fixed size
  19. # you may apply other input transformations here...
  20. img = img.transpose((2,0,1))
  21. X[i] = img
  22. y[i] = float(cls)
  23. z[i] = [1,0,1,1] #Placeholder for real data
  24. with h5py.File('test.h5','w') as H:
  25. H.create_dataset( 'data', data=X ) # note the name X given to the dataset!
  26. H.create_dataset( 'label', data=y ) # note the name y given to the dataset!
  27. H.create_dataset('data2', data=z)
Advertisement
Add Comment
Please, Sign In to add comment