Created
December 21, 2019 08:35
-
-
Save RicherMans/ad23818cf0af8045fa57299a54375b05 to your computer and use it in GitHub Desktop.
HDf5 test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h5py | |
import numpy as np | |
from tqdm import tqdm | |
indices = list(range(100000)) | |
rand_index = np.random.permutation(len(indices)).astype(str) | |
BATCH_SIZE = 128 | |
def batch_gen(): | |
batch = [] | |
for ind in rand_index: | |
batch.append(ind) | |
if len(batch) == BATCH_SIZE: | |
yield batch | |
batch = [] | |
if len(batch) > 0: | |
yield batch | |
with h5py.File('data.h5', 'r') as store, tqdm(total=len(indices)) as pbar: | |
for batch_index in batch_gen(): | |
for ind in sorted(batch_index): | |
# for ind in batch_index: | |
f = store[ind][()] | |
pbar.set_postfix(ind=ind) | |
pbar.update() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h5py | |
import numpy as np | |
from tqdm import tqdm | |
with h5py.File('data.h5','w') as store: | |
for idx in tqdm(range(100000)): | |
x = np.random.normal(size=10000) | |
store[str(idx)] = x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment