This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from mlgill/memory_mapped_data_loading
Memory mapped data loading
- Loading branch information
Showing
5 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from . import io | ||
from . import io_local | ||
from . import constants | ||
from . import model | ||
from . import alignment | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from . import utils | ||
|
||
|
||
def get_array(tensor, keys): | ||
utils.check_mandatory_keys(tensor, keys) | ||
return [tensor[key] for key in keys] | ||
|
||
|
||
def to_hdf5(dictionary, path): | ||
import h5py | ||
|
||
with h5py.File(path, "w") as f: | ||
for key, data in dictionary.items(): | ||
f.create_dataset(key, data=data, dtype=data.dtype, compression="gzip") | ||
|
||
|
||
def from_hdf5(path, n_samples=None): | ||
from keras.utils import HDF5Matrix | ||
import h5py | ||
|
||
# Get a list of the keys for the datasets | ||
with h5py.File(path, 'r') as f: | ||
dataset_list = list(f.keys()) | ||
|
||
# Assemble into a dictionary | ||
data = dict() | ||
for dataset in dataset_list: | ||
data[dataset] = HDF5Matrix(path, dataset, start=0, end=n_samples, normalizer=None) | ||
return data |
This file contains 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
This file contains 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
This file contains 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