def create_hdf5(n_img, path=None, shape=(IMSIZE, IMSIZE, 3), im_dtype=np.float32):
if path is None:
path = '/tmp'
# os.makedirs(path)
tempf = tempfile.NamedTemporaryFile(suffix='.hdf5', dir=path, delete=False)
tempf.close()
with h5py.File(tempf.name, 'w') as f:
f.create_dataset('data', ((n_img, ) + shape), dtype=im_dtype)
f.create_dataset('labels', (n_img, ), dtype=np.int64)
img = np.random.randn(*shape)
label = np.random.randint(1000)
for i in tqdm.trange(n_img, desc='creating hdf5 file'):
f['data'][i] = img
f['labels'][i] = label
return tempf.name
评论列表
文章目录