-
Notifications
You must be signed in to change notification settings - Fork 230
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
Showing
23 changed files
with
561 additions
and
202 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 |
---|---|---|
|
@@ -10,7 +10,7 @@ volumes for training and testing. | |
|
||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:maxdepth: 3 | ||
|
||
patch_training.rst | ||
patch_inference.rst |
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
Empty file.
3 changes: 2 additions & 1 deletion
3
tests/data/test_grid_sampler.py → tests/data/inference/test_grid_sampler.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
Empty file.
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,26 @@ | ||
import torch | ||
import torchio | ||
from torchio.data import LabelSampler | ||
from ...utils import TorchioTestCase | ||
|
||
|
||
class TestLabelSampler(TorchioTestCase): | ||
"""Tests for `LabelSampler` class.""" | ||
|
||
def test_label_sampler(self): | ||
sampler = LabelSampler(5, 'label') | ||
for patch in sampler(self.sample, num_patches=10): | ||
patch_center = patch['label'][torchio.DATA][0, 2, 2, 2] | ||
self.assertEqual(patch_center, 1) | ||
|
||
def test_label_probabilities(self): | ||
labels = torch.Tensor((0, 0, 1, 1, 2, 1, 0)).reshape(1, 1, -1) | ||
subject = torchio.Subject( | ||
label=torchio.Image(tensor=labels, type=torchio.LABEL), | ||
) | ||
sample = torchio.ImagesDataset([subject])[0] | ||
probs_dict = {0: 0, 1: 50, 2: 25, 3: 25} | ||
sampler = LabelSampler(5, 'label', label_probabilities=probs_dict) | ||
probabilities = sampler.get_probability_map(sample) | ||
fixture = torch.Tensor((0, 0, 2/12, 2/12, 3/12, 2/12, 0)) | ||
assert torch.all(probabilities.squeeze().eq(fixture)) |
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,25 @@ | ||
import torch | ||
import torchio | ||
from torchio.data import WeightedSampler | ||
from ...utils import TorchioTestCase | ||
|
||
|
||
class TestWeightedSampler(TorchioTestCase): | ||
"""Tests for `WeightedSampler` class.""" | ||
|
||
def test_weighted_sampler(self): | ||
sample = self.get_sample((7, 7, 7)) | ||
sampler = WeightedSampler(5, 'prob') | ||
patch = next(iter(sampler(sample))) | ||
self.assertEqual(tuple(patch['index_ini']), (1, 1, 1)) | ||
|
||
def get_sample(self, image_shape): | ||
t1 = torch.rand(*image_shape) | ||
prob = torch.zeros_like(t1) | ||
prob[3, 3, 3] = 1 | ||
subject = torchio.Subject( | ||
t1=torchio.Image(tensor=t1), | ||
prob=torchio.Image(tensor=prob), | ||
) | ||
sample = torchio.ImagesDataset([subject])[0] | ||
return sample |
This file was deleted.
Oops, something went wrong.
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
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,2 +1,4 @@ | ||
from .sampler import ImageSampler | ||
from .label import LabelSampler | ||
from .sampler import PatchSampler | ||
from .uniform import UniformSampler | ||
from .weighted import WeightedSampler |
Oops, something went wrong.