-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e5114c
commit 04c297b
Showing
2 changed files
with
89 additions
and
59 deletions.
There are no files selected for viewing
33 changes: 19 additions & 14 deletions
33
applications/physics/cosmology/cosmoflow/cosmoflow_dataset.py
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,31 +1,36 @@ | ||
import numpy as np | ||
from glob import glob | ||
from lbann.util.data import Sample, SampleDims, Dataset, DistConvDataset | ||
from lbann.util.data import Sample, SampleDims, DistConvDataset | ||
import h5py as h5 | ||
import os | ||
|
||
|
||
class CosmoFlowDataset(DistConvDataset): | ||
def __init__(self, data_dir, input_width, num_secrets): | ||
self.data_dir = data_dir | ||
self.input_width = input_width | ||
self.num_secrets = num_secrets | ||
self.samples = glob(os.path.join(data_dir, '*.hdf5')) | ||
self.samples = glob(os.path.join(data_dir, "*.hdf5")) | ||
self.samples.sort() | ||
|
||
def __len__(self): | ||
return len(self.samples) | ||
|
||
def __getitem__(self, index) -> Sample: | ||
data = h5.File(self.samples[index], 'r') | ||
data = h5.File(self.samples[index], "r") | ||
slice_width = self.input_width // self.num_io_partitions | ||
slice_ind = self.rank % self.num_io_partitions | ||
full = data['full'][:, | ||
slice_ind*slice_width:(slice_ind+1)*slice_width, | ||
:self.input_width, | ||
:self.input_width].astype(np.float32) | ||
par = data['unitPar'][:].astype(np.float32) | ||
return Sample(sample=np.ascontiguousarray(full), response=par) | ||
|
||
full = data["full"][ | ||
:, | ||
slice_ind * slice_width : (slice_ind + 1) * slice_width, | ||
: self.input_width, | ||
: self.input_width, | ||
] | ||
par = data["unitPar"][:].astype(np.float32) | ||
return Sample(sample=full, response=par) | ||
|
||
def get_sample_dims(self): | ||
return SampleDims(sample=[4, self.input_width, self.input_width, self.input_width], response=self.num_secrets) | ||
return SampleDims( | ||
sample=[4, self.input_width, self.input_width, self.input_width], | ||
response=self.num_secrets, | ||
) |
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