Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import h5py, os
- import caffe
- import numpy as np
- SIZE = 224 # fixed size to all images
- with open( 'val1.txt', 'r' ) as T :
- lines = T.readlines()
- # If you do not have enough memory split data into
- # multiple batches and generate multiple separate h5 files
- X = np.zeros( (len(lines), 3, SIZE, SIZE), dtype='f4' )
- y = np.zeros( (len(lines),1), dtype='f4' )
- z = np.zeros( (len(lines),4), dtype='f4' )
- print y.shape
- for i,l in enumerate(lines):
- sp = l.split(' ')
- cls= int(sp[1][:-1])
- img = caffe.io.load_image( sp[0] )
- img = caffe.io.resize( img, (SIZE, SIZE, 3) ) # resize to fixed size
- # you may apply other input transformations here...
- img = img.transpose((2,0,1))
- X[i] = img
- y[i] = float(cls)
- z[i] = [1,0,1,1] #Placeholder for real data
- with h5py.File('test.h5','w') as H:
- H.create_dataset( 'data', data=X ) # note the name X given to the dataset!
- H.create_dataset( 'label', data=y ) # note the name y given to the dataset!
- H.create_dataset('data2', data=z)
Advertisement
Add Comment
Please, Sign In to add comment