diff --git a/bob/ip/binseg/configs/datasets/drionsdb.py b/bob/ip/binseg/configs/datasets/drionsdb.py index 2afb6df753625c9d9adea12945d4c32ce0518b7a..24556208cff56c37898021bd5d9b3d291679bb76 100644 --- a/bob/ip/binseg/configs/datasets/drionsdb.py +++ b/bob/ip/binseg/configs/datasets/drionsdb.py @@ -22,8 +22,7 @@ from bob.ip.binseg.data.transforms import Pad from bob.ip.binseg.configs.datasets.utils import DATA_AUGMENTATION as _DA _transforms = [Pad((4, 8, 4, 8))] + _DA -from bob.db.drionsdb import Database as DRIONS -bobdb = DRIONS(protocol="default") - -from bob.ip.binseg.data.binsegdataset import BinSegDataset -dataset = BinSegDataset(bobdb, split="train", transforms=_transforms) +from bob.ip.binseg.data.utils import SampleList2TorchDataset +from bob.ip.binseg.data.drionsdb import dataset as drionsdb +dataset = SampleList2TorchDataset(drionsdb.subsets("default")["train"], + transforms=_transforms) diff --git a/bob/ip/binseg/configs/datasets/drionsdb_test.py b/bob/ip/binseg/configs/datasets/drionsdb_test.py index c57182cf4d28977d75739881c29208e0c13eb560..ed38279ef5ea4b0b96d3d0ef357c91db22ae0a4d 100644 --- a/bob/ip/binseg/configs/datasets/drionsdb_test.py +++ b/bob/ip/binseg/configs/datasets/drionsdb_test.py @@ -21,8 +21,7 @@ baseline. from bob.ip.binseg.data.transforms import Pad _transforms = [Pad((4, 8, 4, 8))] -from bob.db.drionsdb import Database as DRIONS -bobdb = DRIONS(protocol="default") - -from bob.ip.binseg.data.binsegdataset import BinSegDataset -dataset = BinSegDataset(bobdb, split="test", transforms=_transforms) +from bob.ip.binseg.data.utils import SampleList2TorchDataset +from bob.ip.binseg.data.drionsdb import dataset as drionsdb +dataset = SampleList2TorchDataset(drionsdb.subsets("default")["test"], + transforms=_transforms) diff --git a/bob/ip/binseg/data/binsegdataset.py b/bob/ip/binseg/data/binsegdataset.py deleted file mode 100644 index 1a94c0be9679df2ab8dbd38f99e994cd4a1bb674..0000000000000000000000000000000000000000 --- a/bob/ip/binseg/data/binsegdataset.py +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from torch.utils.data import Dataset -import random - -from .transforms import Compose, ToTensor - - -class BinSegDataset(Dataset): - """PyTorch dataset wrapper around bob.db binary segmentation datasets. - A transform object can be passed that will be applied to the image, ground truth and mask (if present). - It supports indexing such that dataset[i] can be used to get ith sample. - - Parameters - ---------- - bobdb : :py:mod:`bob.db.base` - Binary segmentation bob database (e.g. bob.db.drive) - - split : str - ``'train'`` or ``'test'``. Defaults to ``'train'`` - - transforms : :py:class:`list`, Optional - a list of transformations to be applied to **both** image and - ground-truth data. Notice that image changing transformations such as - :py:class:`.transforms.ColorJitter` are only applied to the image and - **not** to ground-truth. Also notice a last transform - (:py:class:`bob.ip.binseg.data.transforms.ToTensor`) is always applied. - - mask : bool - whether dataset contains masks or not - - """ - - def __init__(self, bobdb, split="train", transforms=[], index_to=None): - if index_to: - self.database = bobdb.samples(split)[:index_to] - else: - self.database = bobdb.samples(split) - self.transform = Compose(transforms + [ToTensor()]) - self.split = split - - @property - def mask(self): - # check if first sample contains a mask - return hasattr(self.database[0], "mask") - - def __len__(self): - """ - Returns - ------- - int - size of the dataset - """ - return len(self.database) - - def __getitem__(self, index): - """ - Parameters - ---------- - index : int - - Returns - ------- - list - dataitem [img_name, img, gt] - """ - img = self.database[index].img.pil_image() - gt = self.database[index].gt.pil_image() - img_name = self.database[index].img.basename - sample = [img, gt] - - if self.transform: - sample = self.transform(*sample) - - sample.insert(0, img_name) - - return sample - - -class SSLBinSegDataset(Dataset): - """PyTorch dataset wrapper around bob.db binary segmentation datasets. - A transform object can be passed that will be applied to the image, ground truth and mask (if present). - It supports indexing such that dataset[i] can be used to get ith sample. - - Parameters - ---------- - labeled_dataset : :py:class:`torch.utils.data.Dataset` - BinSegDataset with labeled samples - unlabeled_dataset : :py:class:`torch.utils.data.Dataset` - UnLabeledBinSegDataset with unlabeled data - """ - - def __init__(self, labeled_dataset, unlabeled_dataset): - self.labeled_dataset = labeled_dataset - self.unlabeled_dataset = unlabeled_dataset - - def __len__(self): - """ - Returns - ------- - int - size of the dataset - """ - return len(self.labeled_dataset) - - def __getitem__(self, index): - """ - Parameters - ---------- - index : int - - Returns - ------- - list - dataitem [img_name, img, gt, unlabeled_img_name, unlabeled_img] - """ - sample = self.labeled_dataset[index] - unlabeled_img_name, unlabeled_img = self.unlabeled_dataset[0] - sample.extend([unlabeled_img_name, unlabeled_img]) - return sample - - -class UnLabeledBinSegDataset(Dataset): - # TODO: if switch to handle case were not a bob.db object but a path to a directory is used - """PyTorch dataset wrapper around bob.db binary segmentation datasets. - A transform object can be passed that will be applied to the image, ground truth and mask (if present). - It supports indexing such that dataset[i] can be used to get ith sample. - - Parameters - ---------- - dv : :py:mod:`bob.db.base` or str - Binary segmentation bob database (e.g. bob.db.drive) or path to folder containing unlabeled images - split : str - ``'train'`` or ``'test'``. Defaults to ``'train'`` - transform : :py:mod:`bob.ip.binseg.data.transforms`, optional - A transform or composition of transfroms. Defaults to ``None``. - """ - - def __init__(self, db, split="train", transform=None, index_from=None): - if index_from: - self.database = db.samples(split)[index_from:] - else: - self.database = db.samples(split) - self.transform = transform - self.split = split - - def __len__(self): - """ - Returns - ------- - int - size of the dataset - """ - return len(self.database) - - def __getitem__(self, index): - """ - Parameters - ---------- - index : int - - Returns - ------- - list - dataitem [img_name, img] - """ - random.shuffle(self.database) - img = self.database[index].img.pil_image() - img_name = self.database[index].img.basename - sample = [img] - if self.transform: - sample = self.transform(img) - - sample.insert(0, img_name) - - return sample diff --git a/bob/ip/binseg/data/drionsdb/__init__.py b/bob/ip/binseg/data/drionsdb/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..3e1b5798c45636ebdc7f6169f2f91cdf33288644 --- /dev/null +++ b/bob/ip/binseg/data/drionsdb/__init__.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# coding=utf-8 + +"""DRIONS-DB (training set) for Optic Disc Segmentation + +The dataset originates from data collected from 55 patients with glaucoma +(23.1%) and eye hypertension (76.9%), and random selected from an eye fundus +image base belonging to the Ophthalmology Service at Miguel Servet Hospital, +Saragossa (Spain). It contains 110 eye fundus images with a resolution of 600 +x 400. Two sets of ground-truth optic disc annotations are available. The first +set is commonly used for training and testing. The second set acts as a "human" +baseline. + +* Reference: [DRIONSDB-2008]_ +* Original resolution (height x width): 400 x 600 +* Configuration resolution: 416 x 608 (after padding) +* Split reference: [MANINIS-2016]_ +* Protocols ``default`` and ``expert2``: + + * Training samples: 60 + * Test samples: 50 +""" + +import os +import csv +import pkg_resources + +import PIL.Image +import PIL.ImageDraw + +import bob.extension + +from ..jsondataset import JSONDataset +from ..loader import load_pil_rgb + +_protocols = [ + pkg_resources.resource_filename(__name__, "default.json"), + pkg_resources.resource_filename(__name__, "expert2.json"), + ] + +_root_path = bob.extension.rc.get('bob.ip.binseg.drionsdb.datadir', + os.path.realpath(os.curdir)) + + +def _txt_to_pil_1(fname, size): + """Converts DRIONS-DB annotations to image format""" + with open(fname,'r') as f: + rows = csv.reader(f,delimiter=',',quoting=csv.QUOTE_NONNUMERIC) + data = list(map(tuple,rows)) + + retval = PIL.Image.new('1', size) + draw = PIL.ImageDraw.ImageDraw(retval) + draw.polygon(data, fill='white') + del draw + return retval + + +def _pad_right(img): + """Pads image on the right by one pixel, respects mode""" + retval = PIL.Image.new(img.mode, (img.size[0]+1, img.size[1]), 'black') + retval.paste(img, (0, 0)+img.size) #top-left pasting + return retval + + +def _loader(context, sample): + data = load_pil_rgb(sample["data"]) + label = _txt_to_pil_1(sample["label"], data.size) + + if sample["data"].endswith("_101.jpg"): + # pads the image on the right side to account for a difference in + # resolution to other images in the dataset + data = _pad_right(data) + label = _pad_right(label) + + return dict(data=data, label=label) + +dataset = JSONDataset(protocols=_protocols, root_path=_root_path, loader=_loader) +"""DRIONSDB dataset object""" diff --git a/bob/ip/binseg/data/drionsdb/default.json b/bob/ip/binseg/data/drionsdb/default.json new file mode 100644 index 0000000000000000000000000000000000000000..7486980a2cfc8974d6547ca49ead7b912a08653f --- /dev/null +++ b/bob/ip/binseg/data/drionsdb/default.json @@ -0,0 +1,446 @@ +{ + "train": [ + [ + "images/image_001.jpg", + "experts_anotation/anotExpert1_001.txt" + ], + [ + "images/image_002.jpg", + "experts_anotation/anotExpert1_002.txt" + ], + [ + "images/image_003.jpg", + "experts_anotation/anotExpert1_003.txt" + ], + [ + "images/image_004.jpg", + "experts_anotation/anotExpert1_004.txt" + ], + [ + "images/image_005.jpg", + "experts_anotation/anotExpert1_005.txt" + ], + [ + "images/image_006.jpg", + "experts_anotation/anotExpert1_006.txt" + ], + [ + "images/image_007.jpg", + "experts_anotation/anotExpert1_007.txt" + ], + [ + "images/image_008.jpg", + "experts_anotation/anotExpert1_008.txt" + ], + [ + "images/image_009.jpg", + "experts_anotation/anotExpert1_009.txt" + ], + [ + "images/image_010.jpg", + "experts_anotation/anotExpert1_010.txt" + ], + [ + "images/image_011.jpg", + "experts_anotation/anotExpert1_011.txt" + ], + [ + "images/image_012.jpg", + "experts_anotation/anotExpert1_012.txt" + ], + [ + "images/image_013.jpg", + "experts_anotation/anotExpert1_013.txt" + ], + [ + "images/image_014.jpg", + "experts_anotation/anotExpert1_014.txt" + ], + [ + "images/image_015.jpg", + "experts_anotation/anotExpert1_015.txt" + ], + [ + "images/image_016.jpg", + "experts_anotation/anotExpert1_016.txt" + ], + [ + "images/image_017.jpg", + "experts_anotation/anotExpert1_017.txt" + ], + [ + "images/image_018.jpg", + "experts_anotation/anotExpert1_018.txt" + ], + [ + "images/image_019.jpg", + "experts_anotation/anotExpert1_019.txt" + ], + [ + "images/image_020.jpg", + "experts_anotation/anotExpert1_020.txt" + ], + [ + "images/image_021.jpg", + "experts_anotation/anotExpert1_021.txt" + ], + [ + "images/image_022.jpg", + "experts_anotation/anotExpert1_022.txt" + ], + [ + "images/image_023.jpg", + "experts_anotation/anotExpert1_023.txt" + ], + [ + "images/image_024.jpg", + "experts_anotation/anotExpert1_024.txt" + ], + [ + "images/image_025.jpg", + "experts_anotation/anotExpert1_025.txt" + ], + [ + "images/image_026.jpg", + "experts_anotation/anotExpert1_026.txt" + ], + [ + "images/image_027.jpg", + "experts_anotation/anotExpert1_027.txt" + ], + [ + "images/image_028.jpg", + "experts_anotation/anotExpert1_028.txt" + ], + [ + "images/image_029.jpg", + "experts_anotation/anotExpert1_029.txt" + ], + [ + "images/image_030.jpg", + "experts_anotation/anotExpert1_030.txt" + ], + [ + "images/image_031.jpg", + "experts_anotation/anotExpert1_031.txt" + ], + [ + "images/image_032.jpg", + "experts_anotation/anotExpert1_032.txt" + ], + [ + "images/image_033.jpg", + "experts_anotation/anotExpert1_033.txt" + ], + [ + "images/image_034.jpg", + "experts_anotation/anotExpert1_034.txt" + ], + [ + "images/image_035.jpg", + "experts_anotation/anotExpert1_035.txt" + ], + [ + "images/image_036.jpg", + "experts_anotation/anotExpert1_036.txt" + ], + [ + "images/image_037.jpg", + "experts_anotation/anotExpert1_037.txt" + ], + [ + "images/image_038.jpg", + "experts_anotation/anotExpert1_038.txt" + ], + [ + "images/image_039.jpg", + "experts_anotation/anotExpert1_039.txt" + ], + [ + "images/image_040.jpg", + "experts_anotation/anotExpert1_040.txt" + ], + [ + "images/image_041.jpg", + "experts_anotation/anotExpert1_041.txt" + ], + [ + "images/image_042.jpg", + "experts_anotation/anotExpert1_042.txt" + ], + [ + "images/image_043.jpg", + "experts_anotation/anotExpert1_043.txt" + ], + [ + "images/image_044.jpg", + "experts_anotation/anotExpert1_044.txt" + ], + [ + "images/image_045.jpg", + "experts_anotation/anotExpert1_045.txt" + ], + [ + "images/image_046.jpg", + "experts_anotation/anotExpert1_046.txt" + ], + [ + "images/image_047.jpg", + "experts_anotation/anotExpert1_047.txt" + ], + [ + "images/image_048.jpg", + "experts_anotation/anotExpert1_048.txt" + ], + [ + "images/image_049.jpg", + "experts_anotation/anotExpert1_049.txt" + ], + [ + "images/image_050.jpg", + "experts_anotation/anotExpert1_050.txt" + ], + [ + "images/image_051.jpg", + "experts_anotation/anotExpert1_051.txt" + ], + [ + "images/image_052.jpg", + "experts_anotation/anotExpert1_052.txt" + ], + [ + "images/image_053.jpg", + "experts_anotation/anotExpert1_053.txt" + ], + [ + "images/image_054.jpg", + "experts_anotation/anotExpert1_054.txt" + ], + [ + "images/image_055.jpg", + "experts_anotation/anotExpert1_055.txt" + ], + [ + "images/image_056.jpg", + "experts_anotation/anotExpert1_056.txt" + ], + [ + "images/image_057.jpg", + "experts_anotation/anotExpert1_057.txt" + ], + [ + "images/image_058.jpg", + "experts_anotation/anotExpert1_058.txt" + ], + [ + "images/image_059.jpg", + "experts_anotation/anotExpert1_059.txt" + ], + [ + "images/image_060.jpg", + "experts_anotation/anotExpert1_060.txt" + ] + ], + "test": [ + [ + "images/image_061.jpg", + "experts_anotation/anotExpert1_061.txt" + ], + [ + "images/image_062.jpg", + "experts_anotation/anotExpert1_062.txt" + ], + [ + "images/image_063.jpg", + "experts_anotation/anotExpert1_063.txt" + ], + [ + "images/image_064.jpg", + "experts_anotation/anotExpert1_064.txt" + ], + [ + "images/image_065.jpg", + "experts_anotation/anotExpert1_065.txt" + ], + [ + "images/image_066.jpg", + "experts_anotation/anotExpert1_066.txt" + ], + [ + "images/image_067.jpg", + "experts_anotation/anotExpert1_067.txt" + ], + [ + "images/image_068.jpg", + "experts_anotation/anotExpert1_068.txt" + ], + [ + "images/image_069.jpg", + "experts_anotation/anotExpert1_069.txt" + ], + [ + "images/image_070.jpg", + "experts_anotation/anotExpert1_070.txt" + ], + [ + "images/image_071.jpg", + "experts_anotation/anotExpert1_071.txt" + ], + [ + "images/image_072.jpg", + "experts_anotation/anotExpert1_072.txt" + ], + [ + "images/image_073.jpg", + "experts_anotation/anotExpert1_073.txt" + ], + [ + "images/image_074.jpg", + "experts_anotation/anotExpert1_074.txt" + ], + [ + "images/image_075.jpg", + "experts_anotation/anotExpert1_075.txt" + ], + [ + "images/image_076.jpg", + "experts_anotation/anotExpert1_076.txt" + ], + [ + "images/image_077.jpg", + "experts_anotation/anotExpert1_077.txt" + ], + [ + "images/image_078.jpg", + "experts_anotation/anotExpert1_078.txt" + ], + [ + "images/image_079.jpg", + "experts_anotation/anotExpert1_079.txt" + ], + [ + "images/image_080.jpg", + "experts_anotation/anotExpert1_080.txt" + ], + [ + "images/image_081.jpg", + "experts_anotation/anotExpert1_081.txt" + ], + [ + "images/image_082.jpg", + "experts_anotation/anotExpert1_082.txt" + ], + [ + "images/image_083.jpg", + "experts_anotation/anotExpert1_083.txt" + ], + [ + "images/image_084.jpg", + "experts_anotation/anotExpert1_084.txt" + ], + [ + "images/image_085.jpg", + "experts_anotation/anotExpert1_085.txt" + ], + [ + "images/image_086.jpg", + "experts_anotation/anotExpert1_086.txt" + ], + [ + "images/image_087.jpg", + "experts_anotation/anotExpert1_087.txt" + ], + [ + "images/image_088.jpg", + "experts_anotation/anotExpert1_088.txt" + ], + [ + "images/image_089.jpg", + "experts_anotation/anotExpert1_089.txt" + ], + [ + "images/image_090.jpg", + "experts_anotation/anotExpert1_090.txt" + ], + [ + "images/image_091.jpg", + "experts_anotation/anotExpert1_091.txt" + ], + [ + "images/image_092.jpg", + "experts_anotation/anotExpert1_092.txt" + ], + [ + "images/image_093.jpg", + "experts_anotation/anotExpert1_093.txt" + ], + [ + "images/image_094.jpg", + "experts_anotation/anotExpert1_094.txt" + ], + [ + "images/image_095.jpg", + "experts_anotation/anotExpert1_095.txt" + ], + [ + "images/image_096.jpg", + "experts_anotation/anotExpert1_096.txt" + ], + [ + "images/image_097.jpg", + "experts_anotation/anotExpert1_097.txt" + ], + [ + "images/image_098.jpg", + "experts_anotation/anotExpert1_098.txt" + ], + [ + "images/image_099.jpg", + "experts_anotation/anotExpert1_099.txt" + ], + [ + "images/image_100.jpg", + "experts_anotation/anotExpert1_100.txt" + ], + [ + "images/image_101.jpg", + "experts_anotation/anotExpert1_101.txt" + ], + [ + "images/image_102.jpg", + "experts_anotation/anotExpert1_102.txt" + ], + [ + "images/image_103.jpg", + "experts_anotation/anotExpert1_103.txt" + ], + [ + "images/image_104.jpg", + "experts_anotation/anotExpert1_104.txt" + ], + [ + "images/image_105.jpg", + "experts_anotation/anotExpert1_105.txt" + ], + [ + "images/image_106.jpg", + "experts_anotation/anotExpert1_106.txt" + ], + [ + "images/image_107.jpg", + "experts_anotation/anotExpert1_107.txt" + ], + [ + "images/image_108.jpg", + "experts_anotation/anotExpert1_108.txt" + ], + [ + "images/image_109.jpg", + "experts_anotation/anotExpert1_109.txt" + ], + [ + "images/image_110.jpg", + "experts_anotation/anotExpert1_110.txt" + ] + ] +} \ No newline at end of file diff --git a/bob/ip/binseg/data/drionsdb/expert2.json b/bob/ip/binseg/data/drionsdb/expert2.json new file mode 100644 index 0000000000000000000000000000000000000000..1f3860ce0c2a822f5db5a65c1c4effd3ef8087f5 --- /dev/null +++ b/bob/ip/binseg/data/drionsdb/expert2.json @@ -0,0 +1,446 @@ +{ + "train": [ + [ + "images/image_001.jpg", + "experts_anotation/anotExpert2_001.txt" + ], + [ + "images/image_002.jpg", + "experts_anotation/anotExpert2_002.txt" + ], + [ + "images/image_003.jpg", + "experts_anotation/anotExpert2_003.txt" + ], + [ + "images/image_004.jpg", + "experts_anotation/anotExpert2_004.txt" + ], + [ + "images/image_005.jpg", + "experts_anotation/anotExpert2_005.txt" + ], + [ + "images/image_006.jpg", + "experts_anotation/anotExpert2_006.txt" + ], + [ + "images/image_007.jpg", + "experts_anotation/anotExpert2_007.txt" + ], + [ + "images/image_008.jpg", + "experts_anotation/anotExpert2_008.txt" + ], + [ + "images/image_009.jpg", + "experts_anotation/anotExpert2_009.txt" + ], + [ + "images/image_010.jpg", + "experts_anotation/anotExpert2_010.txt" + ], + [ + "images/image_011.jpg", + "experts_anotation/anotExpert2_011.txt" + ], + [ + "images/image_012.jpg", + "experts_anotation/anotExpert2_012.txt" + ], + [ + "images/image_013.jpg", + "experts_anotation/anotExpert2_013.txt" + ], + [ + "images/image_014.jpg", + "experts_anotation/anotExpert2_014.txt" + ], + [ + "images/image_015.jpg", + "experts_anotation/anotExpert2_015.txt" + ], + [ + "images/image_016.jpg", + "experts_anotation/anotExpert2_016.txt" + ], + [ + "images/image_017.jpg", + "experts_anotation/anotExpert2_017.txt" + ], + [ + "images/image_018.jpg", + "experts_anotation/anotExpert2_018.txt" + ], + [ + "images/image_019.jpg", + "experts_anotation/anotExpert2_019.txt" + ], + [ + "images/image_020.jpg", + "experts_anotation/anotExpert2_020.txt" + ], + [ + "images/image_021.jpg", + "experts_anotation/anotExpert2_021.txt" + ], + [ + "images/image_022.jpg", + "experts_anotation/anotExpert2_022.txt" + ], + [ + "images/image_023.jpg", + "experts_anotation/anotExpert2_023.txt" + ], + [ + "images/image_024.jpg", + "experts_anotation/anotExpert2_024.txt" + ], + [ + "images/image_025.jpg", + "experts_anotation/anotExpert2_025.txt" + ], + [ + "images/image_026.jpg", + "experts_anotation/anotExpert2_026.txt" + ], + [ + "images/image_027.jpg", + "experts_anotation/anotExpert2_027.txt" + ], + [ + "images/image_028.jpg", + "experts_anotation/anotExpert2_028.txt" + ], + [ + "images/image_029.jpg", + "experts_anotation/anotExpert2_029.txt" + ], + [ + "images/image_030.jpg", + "experts_anotation/anotExpert2_030.txt" + ], + [ + "images/image_031.jpg", + "experts_anotation/anotExpert2_031.txt" + ], + [ + "images/image_032.jpg", + "experts_anotation/anotExpert2_032.txt" + ], + [ + "images/image_033.jpg", + "experts_anotation/anotExpert2_033.txt" + ], + [ + "images/image_034.jpg", + "experts_anotation/anotExpert2_034.txt" + ], + [ + "images/image_035.jpg", + "experts_anotation/anotExpert2_035.txt" + ], + [ + "images/image_036.jpg", + "experts_anotation/anotExpert2_036.txt" + ], + [ + "images/image_037.jpg", + "experts_anotation/anotExpert2_037.txt" + ], + [ + "images/image_038.jpg", + "experts_anotation/anotExpert2_038.txt" + ], + [ + "images/image_039.jpg", + "experts_anotation/anotExpert2_039.txt" + ], + [ + "images/image_040.jpg", + "experts_anotation/anotExpert2_040.txt" + ], + [ + "images/image_041.jpg", + "experts_anotation/anotExpert2_041.txt" + ], + [ + "images/image_042.jpg", + "experts_anotation/anotExpert2_042.txt" + ], + [ + "images/image_043.jpg", + "experts_anotation/anotExpert2_043.txt" + ], + [ + "images/image_044.jpg", + "experts_anotation/anotExpert2_044.txt" + ], + [ + "images/image_045.jpg", + "experts_anotation/anotExpert2_045.txt" + ], + [ + "images/image_046.jpg", + "experts_anotation/anotExpert2_046.txt" + ], + [ + "images/image_047.jpg", + "experts_anotation/anotExpert2_047.txt" + ], + [ + "images/image_048.jpg", + "experts_anotation/anotExpert2_048.txt" + ], + [ + "images/image_049.jpg", + "experts_anotation/anotExpert2_049.txt" + ], + [ + "images/image_050.jpg", + "experts_anotation/anotExpert2_050.txt" + ], + [ + "images/image_051.jpg", + "experts_anotation/anotExpert2_051.txt" + ], + [ + "images/image_052.jpg", + "experts_anotation/anotExpert2_052.txt" + ], + [ + "images/image_053.jpg", + "experts_anotation/anotExpert2_053.txt" + ], + [ + "images/image_054.jpg", + "experts_anotation/anotExpert2_054.txt" + ], + [ + "images/image_055.jpg", + "experts_anotation/anotExpert2_055.txt" + ], + [ + "images/image_056.jpg", + "experts_anotation/anotExpert2_056.txt" + ], + [ + "images/image_057.jpg", + "experts_anotation/anotExpert2_057.txt" + ], + [ + "images/image_058.jpg", + "experts_anotation/anotExpert2_058.txt" + ], + [ + "images/image_059.jpg", + "experts_anotation/anotExpert2_059.txt" + ], + [ + "images/image_060.jpg", + "experts_anotation/anotExpert2_060.txt" + ] + ], + "test": [ + [ + "images/image_061.jpg", + "experts_anotation/anotExpert2_061.txt" + ], + [ + "images/image_062.jpg", + "experts_anotation/anotExpert2_062.txt" + ], + [ + "images/image_063.jpg", + "experts_anotation/anotExpert2_063.txt" + ], + [ + "images/image_064.jpg", + "experts_anotation/anotExpert2_064.txt" + ], + [ + "images/image_065.jpg", + "experts_anotation/anotExpert2_065.txt" + ], + [ + "images/image_066.jpg", + "experts_anotation/anotExpert2_066.txt" + ], + [ + "images/image_067.jpg", + "experts_anotation/anotExpert2_067.txt" + ], + [ + "images/image_068.jpg", + "experts_anotation/anotExpert2_068.txt" + ], + [ + "images/image_069.jpg", + "experts_anotation/anotExpert2_069.txt" + ], + [ + "images/image_070.jpg", + "experts_anotation/anotExpert2_070.txt" + ], + [ + "images/image_071.jpg", + "experts_anotation/anotExpert2_071.txt" + ], + [ + "images/image_072.jpg", + "experts_anotation/anotExpert2_072.txt" + ], + [ + "images/image_073.jpg", + "experts_anotation/anotExpert2_073.txt" + ], + [ + "images/image_074.jpg", + "experts_anotation/anotExpert2_074.txt" + ], + [ + "images/image_075.jpg", + "experts_anotation/anotExpert2_075.txt" + ], + [ + "images/image_076.jpg", + "experts_anotation/anotExpert2_076.txt" + ], + [ + "images/image_077.jpg", + "experts_anotation/anotExpert2_077.txt" + ], + [ + "images/image_078.jpg", + "experts_anotation/anotExpert2_078.txt" + ], + [ + "images/image_079.jpg", + "experts_anotation/anotExpert2_079.txt" + ], + [ + "images/image_080.jpg", + "experts_anotation/anotExpert2_080.txt" + ], + [ + "images/image_081.jpg", + "experts_anotation/anotExpert2_081.txt" + ], + [ + "images/image_082.jpg", + "experts_anotation/anotExpert2_082.txt" + ], + [ + "images/image_083.jpg", + "experts_anotation/anotExpert2_083.txt" + ], + [ + "images/image_084.jpg", + "experts_anotation/anotExpert2_084.txt" + ], + [ + "images/image_085.jpg", + "experts_anotation/anotExpert2_085.txt" + ], + [ + "images/image_086.jpg", + "experts_anotation/anotExpert2_086.txt" + ], + [ + "images/image_087.jpg", + "experts_anotation/anotExpert2_087.txt" + ], + [ + "images/image_088.jpg", + "experts_anotation/anotExpert2_088.txt" + ], + [ + "images/image_089.jpg", + "experts_anotation/anotExpert2_089.txt" + ], + [ + "images/image_090.jpg", + "experts_anotation/anotExpert2_090.txt" + ], + [ + "images/image_091.jpg", + "experts_anotation/anotExpert2_091.txt" + ], + [ + "images/image_092.jpg", + "experts_anotation/anotExpert2_092.txt" + ], + [ + "images/image_093.jpg", + "experts_anotation/anotExpert2_093.txt" + ], + [ + "images/image_094.jpg", + "experts_anotation/anotExpert2_094.txt" + ], + [ + "images/image_095.jpg", + "experts_anotation/anotExpert2_095.txt" + ], + [ + "images/image_096.jpg", + "experts_anotation/anotExpert2_096.txt" + ], + [ + "images/image_097.jpg", + "experts_anotation/anotExpert2_097.txt" + ], + [ + "images/image_098.jpg", + "experts_anotation/anotExpert2_098.txt" + ], + [ + "images/image_099.jpg", + "experts_anotation/anotExpert2_099.txt" + ], + [ + "images/image_100.jpg", + "experts_anotation/anotExpert2_100.txt" + ], + [ + "images/image_101.jpg", + "experts_anotation/anotExpert2_101.txt" + ], + [ + "images/image_102.jpg", + "experts_anotation/anotExpert2_102.txt" + ], + [ + "images/image_103.jpg", + "experts_anotation/anotExpert2_103.txt" + ], + [ + "images/image_104.jpg", + "experts_anotation/anotExpert2_104.txt" + ], + [ + "images/image_105.jpg", + "experts_anotation/anotExpert2_105.txt" + ], + [ + "images/image_106.jpg", + "experts_anotation/anotExpert2_106.txt" + ], + [ + "images/image_107.jpg", + "experts_anotation/anotExpert2_107.txt" + ], + [ + "images/image_108.jpg", + "experts_anotation/anotExpert2_108.txt" + ], + [ + "images/image_109.jpg", + "experts_anotation/anotExpert2_109.txt" + ], + [ + "images/image_110.jpg", + "experts_anotation/anotExpert2_110.txt" + ] + ] +} diff --git a/bob/ip/binseg/script/dataset.py b/bob/ip/binseg/script/dataset.py index 940f9ef072a14bdc3c95078f7c336cb705742d4c..c396aa47f7c611a65acf465ba8b21d1f31832e5d 100644 --- a/bob/ip/binseg/script/dataset.py +++ b/bob/ip/binseg/script/dataset.py @@ -27,7 +27,7 @@ def _get_supported_datasets(): retval = [] for k in os.listdir(basedir): candidate = os.path.join(basedir, k) - if os.path.isdir(candidate) and 'test.py' in os.listdir(candidate): + if os.path.isdir(candidate) and '__init__.py' in os.listdir(candidate): retval.append(k) return retval diff --git a/bob/ip/binseg/test/test_config.py b/bob/ip/binseg/test/test_config.py index b3bef5b7c5fba224fb77e3acd68994e1ba37c657..eeae7fbc1f77a53f6d3f8c8bb46667d3cbb4c711 100644 --- a/bob/ip/binseg/test/test_config.py +++ b/bob/ip/binseg/test/test_config.py @@ -279,3 +279,31 @@ def test_drishtigs1_optic_cup_all_test(): nose.tools.eq_(sample[1].dtype, torch.float32) nose.tools.eq_(sample[2].shape, (1, 1760, 2048)) #planes, height, width nose.tools.eq_(sample[2].dtype, torch.float32) + + +@rc_variable_set("bob.ip.binseg.drionsdb.datadir") +def test_drionsdb_default_train(): + + from ..configs.datasets.drionsdb import dataset + nose.tools.eq_(len(dataset), 60) + for sample in dataset: + nose.tools.eq_(len(sample), 3) + assert isinstance(sample[0], str) + nose.tools.eq_(sample[1].shape, (3, 416, 608)) #planes, height, width + nose.tools.eq_(sample[1].dtype, torch.float32) + nose.tools.eq_(sample[2].shape, (1, 416, 608)) #planes, height, width + nose.tools.eq_(sample[2].dtype, torch.float32) + + +@rc_variable_set("bob.ip.binseg.drionsdb.datadir") +def test_drionsdb_default_test(): + + from ..configs.datasets.drionsdb_test import dataset + nose.tools.eq_(len(dataset), 50) + for sample in dataset: + nose.tools.eq_(len(sample), 3) + assert isinstance(sample[0], str) + nose.tools.eq_(sample[1].shape, (3, 416, 608)) #planes, height, width + nose.tools.eq_(sample[1].dtype, torch.float32) + nose.tools.eq_(sample[2].shape, (1, 416, 608)) #planes, height, width + nose.tools.eq_(sample[2].dtype, torch.float32) diff --git a/bob/ip/binseg/test/test_drionsdb.py b/bob/ip/binseg/test/test_drionsdb.py new file mode 100644 index 0000000000000000000000000000000000000000..da7a00723f82d89a64d1c831b96aa4bcd45de1cb --- /dev/null +++ b/bob/ip/binseg/test/test_drionsdb.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# coding=utf-8 + + +"""Tests for DRIONS-DB""" + +import os + +import numpy +import nose.tools +from nose.plugins.attrib import attr + +from ..data.drionsdb import dataset +from .utils import rc_variable_set, count_bw + + +def test_protocol_consistency(): + + for protocol in ("default", "expert2"): + + subset = dataset.subsets(protocol) + nose.tools.eq_(len(subset), 2) + + assert "train" in subset + nose.tools.eq_(len(subset["train"]), 60) + for s in subset["train"]: + assert s.key.startswith(os.path.join("images", "image_0")) + + assert "test" in subset + nose.tools.eq_(len(subset["test"]), 50) + for s in subset["test"]: + assert s.key.startswith(os.path.join("images", "image_")) + + +@rc_variable_set("bob.ip.binseg.drionsdb.datadir") +@attr("slow") +def test_loading(): + + image_size = (600, 400) + + def _check_sample(s, bw_threshold_label): + + data = s.data + assert isinstance(data, dict) + nose.tools.eq_(len(data), 2) + + assert "data" in data + nose.tools.eq_(data["data"].size, image_size) + nose.tools.eq_(data["data"].mode, "RGB") + + assert "label" in data + nose.tools.eq_(data["label"].size, image_size) + nose.tools.eq_(data["label"].mode, "1") + + b, w = count_bw(data["label"]) + assert (b + w) == numpy.prod(image_size), ( + f"Counts of black + white ({b}+{w}) do not add up to total " + f"image size ({numpy.prod(image_size)}) at '{s.key}':label" + ) + assert (w / b) < bw_threshold_label, ( + f"The proportion between black and white pixels " + f"({w}/{b}={w/b:.3f}) is larger than the allowed threshold " + f"of {bw_threshold_label} at '{s.key}':label - this could " + f"indicate a loading problem!" + ) + + # to visualize images, uncomment the folowing code + # it should display an image with a faded background representing the + # original data, blended with green labels. + #from ..data.utils import overlayed_image + #display = overlayed_image(data["data"], data["label"]) + #display.show() + #import ipdb; ipdb.set_trace() + + return w/b + + limit = None #use this to limit testing to first images only + subset = dataset.subsets("default") + proportions = [_check_sample(s, 0.046) for s in subset["train"][:limit]] + #print(f"max label proportions = {max(proportions)}") + proportions = [_check_sample(s, 0.043) for s in subset["test"][:limit]] + #print(f"max label proportions = {max(proportions)}") + + subset = dataset.subsets("expert2") + proportions = [_check_sample(s, 0.044) for s in subset["train"][:limit]] + #print(f"max label proportions = {max(proportions)}") + proportions = [_check_sample(s, 0.045) for s in subset["test"][:limit]] + #print(f"max label proportions = {max(proportions)}") + +@rc_variable_set("bob.ip.binseg.drionsdb.datadir") +@attr("slow") +def test_check(): + nose.tools.eq_(dataset.check(), 0) diff --git a/conda/meta.yaml b/conda/meta.yaml index a4082688604c7423c1ad502438d275b8a6fd6491..a6e591aa6c590bb61dc4358b47d830c65b03cc2b 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -59,7 +59,6 @@ test: - sphinx - sphinx_rtd_theme - sphinxcontrib-programoutput - - bob.db.drionsdb about: summary: Binary Segmentation Benchmark Package for Bob diff --git a/doc/api.rst b/doc/api.rst index 6b6a682e39829650de79ba0e46465940888d0d53..4e70a851f03a4af60faa1e24fbbb1360190088ca 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -15,7 +15,6 @@ Data Manipulation .. autosummary:: :toctree: api/data - bob.ip.binseg.data.binsegdataset bob.ip.binseg.data.folderdataset bob.ip.binseg.data.csvdataset bob.ip.binseg.data.jsondataset @@ -39,6 +38,7 @@ Datasets bob.ip.binseg.data.refuge bob.ip.binseg.data.drishtigs1 bob.ip.binseg.data.rimoner3 + bob.ip.binseg.data.drionsdb Engines @@ -165,14 +165,6 @@ Datasets bob.ip.binseg.configs.datasets.covd_stare bob.ip.binseg.configs.datasets.covd_stare_ssl - bob.ip.binseg.configs.datasets.drionsdb - bob.ip.binseg.configs.datasets.drionsdb_test - - bob.ip.binseg.configs.datasets.dristhigs1_cup - bob.ip.binseg.configs.datasets.dristhigs1_cup_test - bob.ip.binseg.configs.datasets.dristhigs1_od - bob.ip.binseg.configs.datasets.dristhigs1_od_test - bob.ip.binseg.configs.datasets.refuge_cup bob.ip.binseg.configs.datasets.refuge_cup_dev bob.ip.binseg.configs.datasets.refuge_cup_test @@ -185,3 +177,11 @@ Datasets bob.ip.binseg.configs.datasets.rimoner3_cup_test bob.ip.binseg.configs.datasets.rimoner3_od bob.ip.binseg.configs.datasets.rimoner3_od_test + + bob.ip.binseg.configs.datasets.dristhigs1_cup + bob.ip.binseg.configs.datasets.dristhigs1_cup_test + bob.ip.binseg.configs.datasets.dristhigs1_od + bob.ip.binseg.configs.datasets.dristhigs1_od_test + + bob.ip.binseg.configs.datasets.drionsdb + bob.ip.binseg.configs.datasets.drionsdb_test diff --git a/doc/extra-intersphinx.txt b/doc/extra-intersphinx.txt index 37f700a78ecad7bea22172702e640797d7136a17..ac988bdf8417d99a3c45236479862b18684c79f5 100644 --- a/doc/extra-intersphinx.txt +++ b/doc/extra-intersphinx.txt @@ -1,2 +1,2 @@ torch -torchvision \ No newline at end of file +torchvision diff --git a/doc/nitpick-exceptions.txt b/doc/nitpick-exceptions.txt index e508f84b7ed7097f6e06c372f43013ec93aef711..4237c341319162532cd53dd45d34c15c8bbc3226 100644 --- a/doc/nitpick-exceptions.txt +++ b/doc/nitpick-exceptions.txt @@ -1,4 +1,3 @@ -py:mod bob.db.base py:class torch.nn.modules.loss._Loss py:class Module py:class click.core.Option