diff --git a/bob/ip/binseg/configs/datasets/chasedb1/mtest.py b/bob/ip/binseg/configs/datasets/chasedb1/mtest.py new file mode 100644 index 0000000000000000000000000000000000000000..0860d97209d2dcc4ceef736d9f962ddd5dea4776 --- /dev/null +++ b/bob/ip/binseg/configs/datasets/chasedb1/mtest.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# coding=utf-8 + +"""CHASE-DB1 cross-evaluation dataset with matched resolution + +* Configuration resolution (height x width): 960 x 960 +""" + +from bob.ip.binseg.data.transforms import CenterCrop, Pad, Resize +from bob.ip.binseg.configs.datasets.chasedb1.xtest import dataset as _xt + +dataset = { + "train": _xt["train"], + "test": _xt["test"], + "drive": _xt["drive"].copy([CenterCrop((544, 544)), Resize(960)]), + "stare": _xt["stare"].copy( + [Pad((0, 32, 0, 32)), Resize(960), CenterCrop(960)] + ), + "hrf": _xt["hrf"].copy([Pad((0, 584, 0, 584)), Resize(960)]), + "iostar": _xt["iostar"].copy([Resize(960)]), +} diff --git a/bob/ip/binseg/configs/datasets/drive/mtest.py b/bob/ip/binseg/configs/datasets/drive/mtest.py new file mode 100644 index 0000000000000000000000000000000000000000..201e7b898cf87bda98640f3081e659450226331c --- /dev/null +++ b/bob/ip/binseg/configs/datasets/drive/mtest.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# coding=utf-8 + +"""DRIVE cross-evaluation dataset with matched resolution + +* Configuration resolution: 544 x 544 +""" + +from bob.ip.binseg.data.transforms import Resize, Pad, Crop +from bob.ip.binseg.configs.datasets.drive.xtest import dataset as _xt + +dataset = { + "train": _xt["train"], + "test": _xt["test"], + "stare": _xt["stare"].copy([Resize(471), Pad((0, 37, 0, 36))]), + "chasedb1": _xt["chasedb1"].copy([Resize(544), Crop(0, 12, 544, 544)]), + "hrf": _xt["hrf"].copy([Resize((363)), Pad((0, 90, 0, 91))]), + "iostar": _xt["iostar"].copy([Resize(544)]), + } diff --git a/bob/ip/binseg/configs/datasets/hrf/mtest.py b/bob/ip/binseg/configs/datasets/hrf/mtest.py new file mode 100644 index 0000000000000000000000000000000000000000..b5f8f646f4000ddcd89405e379899f45ec5c56b8 --- /dev/null +++ b/bob/ip/binseg/configs/datasets/hrf/mtest.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# coding=utf-8 + +"""HRF cross-evaluation dataset with matched resolution + +* Configuration resolution: 1168 x 1648 +""" + +from bob.ip.binseg.data.transforms import Crop, Pad, Resize +from bob.ip.binseg.configs.datasets.hrf.xtest import dataset as _xt + +dataset = { + "train": _xt["train"], + "test": _xt["test"], + "drive": _xt["drive"].copy( + [Crop(75, 10, 416, 544), Pad((21, 0, 22, 0)), Resize(1168)] + ), + "stare": _xt["stare"].copy( + [Crop(50, 0, 500, 705), Resize(1168), Pad((1, 0, 1, 0))] + ), + "chasedb1": _xt["chasedb1"].copy([Crop(140, 18, 680, 960), Resize(1168)]), + "iostar": _xt["iostar"].copy( + [Crop(144, 0, 768, 1024), Pad((30, 0, 30, 0)), Resize(1168)] + ), +} diff --git a/bob/ip/binseg/configs/datasets/iostar/vessel_mtest.py b/bob/ip/binseg/configs/datasets/iostar/vessel_mtest.py new file mode 100644 index 0000000000000000000000000000000000000000..c89cf204442060247639277b82a8e77affd05295 --- /dev/null +++ b/bob/ip/binseg/configs/datasets/iostar/vessel_mtest.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# coding=utf-8 + +"""IOSTAR vessel cross-evaluation dataset with matched resolution + +* Configuration resolution: 1024 x 1024 +""" + +from bob.ip.binseg.data.transforms import CenterCrop, Crop, Pad, Resize +from bob.ip.binseg.configs.datasets.iostar.vessel_xtest import dataset as _xt + +dataset = { + "train": _xt["train"], + "test": _xt["test"], + "drive": _xt["drive"].copy([CenterCrop((540, 540)), Resize(1024)]), + "stare": _xt["stare"].copy( + [Pad((0, 32, 0, 32)), Resize(1024), CenterCrop(1024)] + ), + "chasedb1": _xt["chasedb1"].copy([Crop(0, 18, 960, 960), Resize(1024)]), + "hrf": _xt["hrf"].copy([Pad((0, 584, 0, 584)), Resize(1024)]), +} diff --git a/bob/ip/binseg/configs/datasets/stare/mtest.py b/bob/ip/binseg/configs/datasets/stare/mtest.py new file mode 100644 index 0000000000000000000000000000000000000000..4485ff815404e09e306aa47c7f8c1f560b877227 --- /dev/null +++ b/bob/ip/binseg/configs/datasets/stare/mtest.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# coding=utf-8 + +"""STARE cross-evaluation dataset with matched resolution + +* Configuration resolution: 704 x 608 +""" + +from bob.ip.binseg.data.transforms import CenterCrop, Pad, Resize +from bob.ip.binseg.configs.datasets.stare.xtest import dataset as _xt + +dataset = { + "train": _xt["train"], + "test": _xt["test"], + "drive": _xt["drive"].copy( + [CenterCrop((470, 544)), Pad((10, 9, 10, 8)), Resize(608)] + ), + "chasedb1": _xt["chasedb1"].copy([CenterCrop((829, 960)), Resize(608)]), + "hrf": _xt["hrf"].copy([Pad((0, 345, 0, 345)), Resize(608)]), + "iostar": _xt["iostar"].copy([Pad((81, 0, 81, 0)), Resize(608)]), +} diff --git a/bob/ip/binseg/data/utils.py b/bob/ip/binseg/data/utils.py index 3d77e9c37e4888adcaa852ea31a7085648437140..2d1439a63e774d7270e76ca9b1fd3f030d6aec72 100644 --- a/bob/ip/binseg/data/utils.py +++ b/bob/ip/binseg/data/utils.py @@ -125,6 +125,16 @@ class SampleListDataset(torch.utils.data.Dataset): It supports indexing such that dataset[i] can be used to get ith sample. + Attributes + ---------- + + transforms : list + An accessor to the list of transforms to be applied (excluding the last + transform, which is fixed). Notice that, after setting, a last transform + (:py:class:`bob.ip.binseg.data.transforms.ToTensor`) is always applied + - you do not need to add that. + + Parameters ---------- @@ -134,14 +144,36 @@ class SampleListDataset(torch.utils.data.Dataset): transforms : :py:class:`list`, Optional a list of transformations to be applied to **both** image and ground-truth data. Notice a last transform - (:py:class:`bob.ip.binseg.data.transforms.ToTensor`) is always applied. + (:py:class:`bob.ip.binseg.data.transforms.ToTensor`) is always applied + - you do not need to add that. """ def __init__(self, samples, transforms=[]): self._samples = samples - self._transforms = Compose(transforms + [ToTensor()]) + self.transforms = transforms + + @property + def transforms(self): + return self._transforms.transforms[:-1] + + @transforms.setter + def transforms(self, l): + self._transforms = Compose(l + [ToTensor()]) + + def copy(self, transforms=None): + """Returns a deep copy of itself, optionally resetting transforms + + Parameters + ---------- + + transforms : :py:class:`list`, Optional + An optional list of transforms to set in the copy. If not + specified, use ``self.transforms``. + """ + + return SampleListDataset(self._samples, transforms or self.transforms) def __len__(self): """ diff --git a/bob/ip/binseg/test/test_config.py b/bob/ip/binseg/test/test_config.py index 10d08e49e8fbb88fb024736842b94bd84326c968..52e3a2b3258485e752cb0887b80bb72e6f05cda4 100644 --- a/bob/ip/binseg/test/test_config.py +++ b/bob/ip/binseg/test/test_config.py @@ -45,7 +45,35 @@ def test_drive(): _check_subset(dataset["test"], 20) -@rc_variable_set("bob.ip.binseg.stare.datadir") +@rc_variable_set("bob.ip.binseg.drive.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") +@rc_variable_set("bob.ip.binseg.chasedb1.datadir") +@rc_variable_set("bob.ip.binseg.hrf.datadir") +@rc_variable_set("bob.ip.binseg.iostar.datadir") +def test_drive_mtest(): + + from ..configs.datasets.drive.mtest import dataset + nose.tools.eq_(len(dataset), 6) + + from ..configs.datasets.drive.default import dataset as baseline + nose.tools.eq_(dataset["train"], baseline["train"]) + nose.tools.eq_(dataset["test"], baseline["test"]) + + for subset in dataset: + for sample in dataset[subset]: + assert 3 <= len(sample) <= 4 + assert isinstance(sample[0], str) + nose.tools.eq_(sample[1].shape, (3, 544, 544)) #planes, height, width + nose.tools.eq_(sample[1].dtype, torch.float32) + nose.tools.eq_(sample[2].shape, (1, 544, 544)) + nose.tools.eq_(sample[2].dtype, torch.float32) + if len(sample) == 4: + nose.tools.eq_(sample[3].shape, (1, 544, 544)) + nose.tools.eq_(sample[3].dtype, torch.float32) + + +@rc_variable_set("bob.ip.binseg.drive.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") @rc_variable_set("bob.ip.binseg.chasedb1.datadir") @rc_variable_set("bob.ip.binseg.hrf.datadir") @rc_variable_set("bob.ip.binseg.iostar.datadir") @@ -74,7 +102,7 @@ def test_drive_covd(): @rc_variable_set("bob.ip.binseg.drive.datadir") -@rc_variable_set("bob.ip.binseg.stare.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") @rc_variable_set("bob.ip.binseg.chasedb1.datadir") @rc_variable_set("bob.ip.binseg.hrf.datadir") @rc_variable_set("bob.ip.binseg.iostar.datadir") @@ -150,6 +178,34 @@ def test_stare(): _check_subset(dataset["test"], 10) +@rc_variable_set("bob.ip.binseg.drive.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") +@rc_variable_set("bob.ip.binseg.chasedb1.datadir") +@rc_variable_set("bob.ip.binseg.hrf.datadir") +@rc_variable_set("bob.ip.binseg.iostar.datadir") +def test_stare_mtest(): + + from ..configs.datasets.stare.mtest import dataset + nose.tools.eq_(len(dataset), 6) + + from ..configs.datasets.stare.ah import dataset as baseline + nose.tools.eq_(dataset["train"], baseline["train"]) + nose.tools.eq_(dataset["test"], baseline["test"]) + + for subset in dataset: + for sample in dataset[subset]: + assert 3 <= len(sample) <= 4 + assert isinstance(sample[0], str) + nose.tools.eq_(sample[1].shape, (3, 608, 704)) #planes,height,width + nose.tools.eq_(sample[1].dtype, torch.float32) + nose.tools.eq_(sample[2].shape, (1, 608, 704)) #planes,height,width + nose.tools.eq_(sample[2].dtype, torch.float32) + if len(sample) == 4: + nose.tools.eq_(sample[3].shape, (1, 608, 704)) + nose.tools.eq_(sample[3].dtype, torch.float32) + + +@stare_variable_set("bob.ip.binseg.stare.datadir") @rc_variable_set("bob.ip.binseg.drive.datadir") @rc_variable_set("bob.ip.binseg.chasedb1.datadir") @rc_variable_set("bob.ip.binseg.hrf.datadir") @@ -200,7 +256,35 @@ def test_chasedb1(): @rc_variable_set("bob.ip.binseg.drive.datadir") -@rc_variable_set("bob.ip.binseg.stare.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") +@rc_variable_set("bob.ip.binseg.chasedb1.datadir") +@rc_variable_set("bob.ip.binseg.hrf.datadir") +@rc_variable_set("bob.ip.binseg.iostar.datadir") +def test_chasedb1_mtest(): + + from ..configs.datasets.chasedb1.mtest import dataset + nose.tools.eq_(len(dataset), 6) + + from ..configs.datasets.chasedb1.first_annotator import dataset as baseline + nose.tools.eq_(dataset["train"], baseline["train"]) + nose.tools.eq_(dataset["test"], baseline["test"]) + + for subset in dataset: + for sample in dataset[subset]: + assert 3 <= len(sample) <= 4 + assert isinstance(sample[0], str) + nose.tools.eq_(sample[1].shape, (3, 960, 960)) #planes,height,width + nose.tools.eq_(sample[1].dtype, torch.float32) + nose.tools.eq_(sample[2].shape, (1, 960, 960)) #planes,height,width + nose.tools.eq_(sample[2].dtype, torch.float32) + if len(sample) == 4: + nose.tools.eq_(sample[3].shape, (1, 960, 960)) + nose.tools.eq_(sample[3].dtype, torch.float32) + + +@rc_variable_set("bob.ip.binseg.drive.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") +@rc_variable_set("bob.ip.binseg.chasedb1.datadir") @rc_variable_set("bob.ip.binseg.hrf.datadir") @rc_variable_set("bob.ip.binseg.iostar.datadir") def test_chasedb1_covd(): @@ -249,8 +333,36 @@ def test_hrf(): @rc_variable_set("bob.ip.binseg.drive.datadir") -@rc_variable_set("bob.ip.binseg.stare.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") @rc_variable_set("bob.ip.binseg.chasedb1.datadir") +@rc_variable_set("bob.ip.binseg.hrf.datadir") +@rc_variable_set("bob.ip.binseg.iostar.datadir") +def test_hrf_mtest(): + + from ..configs.datasets.hrf.mtest import dataset + nose.tools.eq_(len(dataset), 6) + + from ..configs.datasets.hrf.default import dataset as baseline + nose.tools.eq_(dataset["train"], baseline["train"]) + nose.tools.eq_(dataset["test"], baseline["test"]) + + for subset in dataset: + for sample in dataset[subset]: + assert 3 <= len(sample) <= 4 + assert isinstance(sample[0], str) + nose.tools.eq_(sample[1].shape, (3, 1168, 1648)) #planes,height,width + nose.tools.eq_(sample[1].dtype, torch.float32) + nose.tools.eq_(sample[2].shape, (1, 1168, 1648)) #planes,height,width + nose.tools.eq_(sample[2].dtype, torch.float32) + if len(sample) == 4: + nose.tools.eq_(sample[3].shape, (1, 1168, 1648)) + nose.tools.eq_(sample[3].dtype, torch.float32) + + +@rc_variable_set("bob.ip.binseg.drive.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") +@rc_variable_set("bob.ip.binseg.chasedb1.datadir") +@rc_variable_set("bob.ip.binseg.hrf.datadir") @rc_variable_set("bob.ip.binseg.iostar.datadir") def test_hrf_covd(): @@ -300,9 +412,37 @@ def test_iostar(): @rc_variable_set("bob.ip.binseg.drive.datadir") -@rc_variable_set("bob.ip.binseg.stare.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") +@rc_variable_set("bob.ip.binseg.chasedb1.datadir") +@rc_variable_set("bob.ip.binseg.hrf.datadir") +@rc_variable_set("bob.ip.binseg.iostar.datadir") +def test_iostar_mtest(): + + from ..configs.datasets.iostar.vessel_mtest import dataset + nose.tools.eq_(len(dataset), 6) + + from ..configs.datasets.iostar.vessel import dataset as baseline + nose.tools.eq_(dataset["train"], baseline["train"]) + nose.tools.eq_(dataset["test"], baseline["test"]) + + for subset in dataset: + for sample in dataset[subset]: + assert 3 <= len(sample) <= 4 + assert isinstance(sample[0], str) + nose.tools.eq_(sample[1].shape, (3, 1024, 1024)) #planes,height,width + nose.tools.eq_(sample[1].dtype, torch.float32) + nose.tools.eq_(sample[2].shape, (1, 1024, 1024)) #planes,height,width + nose.tools.eq_(sample[2].dtype, torch.float32) + if len(sample) == 4: + nose.tools.eq_(sample[3].shape, (1, 1024, 1024)) + nose.tools.eq_(sample[3].dtype, torch.float32) + + +@rc_variable_set("bob.ip.binseg.drive.datadir") +@stare_variable_set("bob.ip.binseg.stare.datadir") @rc_variable_set("bob.ip.binseg.chasedb1.datadir") @rc_variable_set("bob.ip.binseg.hrf.datadir") +@rc_variable_set("bob.ip.binseg.iostar.datadir") def test_iostar_covd(): from ..configs.datasets.iostar.covd import dataset diff --git a/doc/api.rst b/doc/api.rst index c73aedd230a6c441868f46e6d6e5009e04a79be3..8d145ad5534429edf24cc0be8286449ab86f93a9 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -138,23 +138,27 @@ Datasets bob.ip.binseg.configs.datasets.chasedb1.first_annotator bob.ip.binseg.configs.datasets.chasedb1.second_annotator bob.ip.binseg.configs.datasets.chasedb1.xtest + bob.ip.binseg.configs.datasets.chasedb1.mtest bob.ip.binseg.configs.datasets.chasedb1.covd bob.ip.binseg.configs.datasets.chasedb1.ssl bob.ip.binseg.configs.datasets.drive.default bob.ip.binseg.configs.datasets.drive.second_annotator bob.ip.binseg.configs.datasets.drive.xtest + bob.ip.binseg.configs.datasets.drive.mtest bob.ip.binseg.configs.datasets.drive.covd bob.ip.binseg.configs.datasets.drive.ssl bob.ip.binseg.configs.datasets.hrf.default bob.ip.binseg.configs.datasets.hrf.xtest + bob.ip.binseg.configs.datasets.hrf.mtest bob.ip.binseg.configs.datasets.hrf.default_fullres bob.ip.binseg.configs.datasets.hrf.covd bob.ip.binseg.configs.datasets.hrf.ssl bob.ip.binseg.configs.datasets.iostar.vessel bob.ip.binseg.configs.datasets.iostar.vessel_xtest + bob.ip.binseg.configs.datasets.iostar.vessel_mtest bob.ip.binseg.configs.datasets.iostar.optic_disc bob.ip.binseg.configs.datasets.iostar.covd bob.ip.binseg.configs.datasets.iostar.ssl @@ -162,6 +166,7 @@ Datasets bob.ip.binseg.configs.datasets.stare.ah bob.ip.binseg.configs.datasets.stare.vk bob.ip.binseg.configs.datasets.stare.xtest + bob.ip.binseg.configs.datasets.stare.mtest bob.ip.binseg.configs.datasets.stare.covd bob.ip.binseg.configs.datasets.stare.ssl diff --git a/setup.py b/setup.py index 11b08d12091a66218622e888af7ac1911f04e8a9..bff45cf36196001418a51894c65f90f82d3066e2 100644 --- a/setup.py +++ b/setup.py @@ -62,6 +62,7 @@ setup( "drive = bob.ip.binseg.configs.datasets.drive.default", "drive-2nd = bob.ip.binseg.configs.datasets.drive.second_annotator", "drive-xtest = bob.ip.binseg.configs.datasets.drive.xtest", + "drive-mtest = bob.ip.binseg.configs.datasets.drive.mtest", "drive-covd = bob.ip.binseg.configs.datasets.drive.covd", "drive-ssl = bob.ip.binseg.configs.datasets.drive.ssl", @@ -69,12 +70,14 @@ setup( "stare = bob.ip.binseg.configs.datasets.stare.ah", "stare-2nd = bob.ip.binseg.configs.datasets.stare.vk", "stare-xtest = bob.ip.binseg.configs.datasets.stare.xtest", + "stare-mtest = bob.ip.binseg.configs.datasets.stare.mtest", "stare-covd = bob.ip.binseg.configs.datasets.stare.covd", "stare-ssl = bob.ip.binseg.configs.datasets.stare.ssl", # iostar "iostar-vessel = bob.ip.binseg.configs.datasets.iostar.vessel", "iostar-vessel-xtest = bob.ip.binseg.configs.datasets.iostar.vessel_xtest", + "iostar-vessel-mtest = bob.ip.binseg.configs.datasets.iostar.vessel_mtest", "iostar-disc = bob.ip.binseg.configs.datasets.iostar.optic_disc", "iostar-vessel-covd = bob.ip.binseg.configs.datasets.iostar.covd", "iostar-vessel-ssl = bob.ip.binseg.configs.datasets.iostar.ssl", @@ -82,6 +85,7 @@ setup( # hrf "hrf = bob.ip.binseg.configs.datasets.hrf.default", "hrf-xtest = bob.ip.binseg.configs.datasets.hrf.xtest", + "hrf-mtest = bob.ip.binseg.configs.datasets.hrf.mtest", "hrf-highres = bob.ip.binseg.configs.datasets.hrf.default_fullres", "hrf-covd = bob.ip.binseg.configs.datasets.hrf.covd", "hrf-ssl = bob.ip.binseg.configs.datasets.hrf.ssl", @@ -90,6 +94,7 @@ setup( "chasedb1 = bob.ip.binseg.configs.datasets.chasedb1.first_annotator", "chasedb1-2nd = bob.ip.binseg.configs.datasets.chasedb1.second_annotator", "chasedb1-xtest = bob.ip.binseg.configs.datasets.chasedb1.xtest", + "chasedb1-mtest = bob.ip.binseg.configs.datasets.chasedb1.mtest", "chasedb1-covd = bob.ip.binseg.configs.datasets.chasedb1.covd", "chasedb1-ssl = bob.ip.binseg.configs.datasets.chasedb1.ssl",