This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add doc strings and tests for volume loader
- Loading branch information
1 parent
0cbaf1d
commit 175af35
Showing
2 changed files
with
109 additions
and
0 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
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,57 @@ | ||
import unittest | ||
import os | ||
from shutil import rmtree | ||
|
||
import numpy as np | ||
import h5py | ||
|
||
|
||
class TestVolumeLoader(unittest.TestCase): | ||
shape = (100, 100, 100) | ||
def setUp(self): | ||
self.data = np.random.rand(*self.shape) | ||
|
||
def test_loader(self): | ||
from inferno.io.volumetric import VolumeLoader | ||
loader = VolumeLoader(self.data, | ||
window_size=(10, 10, 10), | ||
stride=(10, 10, 10), return_index_spec=True) | ||
for batch, idx in loader: | ||
slice_ = loader.base_sequence[int(idx)] | ||
expected = self.data[slice_] | ||
self.assertEqual(batch.shape, expected.shape) | ||
self.assertTrue(np.allclose(batch, expected)) | ||
|
||
|
||
class TestHDF5VolumeLoader(unittest.TestCase): | ||
shape = (100, 100, 100) | ||
def setUp(self): | ||
try: | ||
os.mkdir('./tmp') | ||
except OSError: | ||
pass | ||
self.data = np.random.rand(*self.shape) | ||
with h5py.File('./tmp/data.h5') as f: | ||
f.create_dataset('data', data=self.data) | ||
|
||
def tearDown(self): | ||
try: | ||
rmtree('./tmp') | ||
except OSError: | ||
pass | ||
|
||
def test_hdf5_loader(self): | ||
from inferno.io.volumetric import HDF5VolumeLoader | ||
loader = HDF5VolumeLoader('./tmp/data.h5', 'data', | ||
window_size=(10, 10, 10), | ||
stride=(10, 10, 10), return_index_spec=True) | ||
for batch, idx in loader: | ||
slice_ = loader.base_sequence[int(idx)] | ||
expected = self.data[slice_] | ||
self.assertEqual(batch.shape, expected.shape) | ||
self.assertTrue(np.allclose(batch, expected)) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |