diff --git a/bob/ip/binseg/configs/datasets/imagefolder.py b/bob/ip/binseg/configs/datasets/imagefolder.py new file mode 100644 index 0000000000000000000000000000000000000000..efcf2879a27973e01badf328a71efa265c9fa7f7 --- /dev/null +++ b/bob/ip/binseg/configs/datasets/imagefolder.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from bob.ip.binseg.data.transforms import * +from bob.ip.binseg.data.imagefolder import ImageFolder + +#### Config #### + +# add your transforms below +transforms = Compose([ + CenterCrop((544,544)) + ,RandomHFlip() + ,RandomVFlip() + ,RandomRotation() + ,ColorJitter() + ,ToTensor() + ]) + +# PyTorch dataset +path = '/path/to/dataset' +dataset = ImageFolder(path,transform=transforms) diff --git a/bob/ip/binseg/data/imagefolder.py b/bob/ip/binseg/data/imagefolder.py new file mode 100644 index 0000000000000000000000000000000000000000..3f71f4e1d518b0c41b2e6bb8e3b0267b16c1874d --- /dev/null +++ b/bob/ip/binseg/data/imagefolder.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from torch.utils.data import Dataset +from pathlib import Path +import numpy as np +from PIL import Image +import torch +import torchvision.transforms.functional as VF + +def get_file_lists(data_path): + data_path = Path(data_path) + + image_path = data_path.joinpath('images') + image_file_names = np.array(sorted(list(image_path.glob('*')))) + + gt_path = data_path.joinpath('gt') + gt_file_names = np.array(sorted(list(gt_path.glob('*')))) + return image_file_names, gt_file_names + +class ImageFolder(Dataset): + """ + Required directory tree structure for images and ground-truth (gt): + root + |- images + |- gt + + + Parameters + ---------- + path : str + full path to root of dataset + + Returns + ------- + [type] + [description] + """ + def __init__(self, path, transform = None): + self.transform = transform + self.img_file_list, self.gt_file_list = get_file_lists(path) + + def __len__(self): + """ + Returns + ------- + int + size of the dataset + """ + return len(self.img_file_list) + + def __getitem__(self,index): + """ + Parameters + ---------- + index : int + + Returns + ------- + list + dataitem [img_name, img, gt, mask] + """ + img_path = self.img_file_list[index] + img_name = img_path.name + img = Image.open(img_path).convert(mode='RGB') + + gt_path = self.gt_file_list[index] + gt = Image.open(gt_path).convert(mode='1', dither=None) + sample = [img, gt] + + if self.transform : + sample = self.transform(*sample) + + sample.insert(0,img_name) + + return sample diff --git a/doc/configs.rst b/doc/configs.rst index 643e2fbc7e1b33e5749b1d01e7023ff66d5d5845..a45e2986ec489bc5216e3512c4b7acbe39454051 100644 --- a/doc/configs.rst +++ b/doc/configs.rst @@ -8,6 +8,13 @@ Configs Dataset Configs =============== +.. _bob.ip.binseg.configs.datasets.imagefolder: + +ImageFolder +---------------- +.. literalinclude:: ../bob/ip/binseg/configs/datasets/imagefolder.py + + .. _bob.ip.binseg.configs.datasets.chasedb1: CHASEDB1 diff --git a/doc/datasets.rst b/doc/datasets.rst index 64a0efa8cd145c0574554babc64abd112b54ff59..9e00c4398734b28be0990ef77c3ecc7b59935822 100644 --- a/doc/datasets.rst +++ b/doc/datasets.rst @@ -33,9 +33,16 @@ Supported Datasets Add-on: Folder-based Dataset ============================ -For quick experimentation we also provide a PyTorch class that works with a -dataset folder structure: +For quick experimentation we also provide a PyTorch class that works with the following +dataset folder structure for images and ground-truth (gt): +.. code-block:: bash + root + |- images + |- gt + +In the dataset config :ref:`bob.ip.binseg.configs.datasets.imagefolder` the full path of the dataset has to be amended. Training can then for example be started with +``bob binseg train M2UNet IMAGEFOLDER -b 4 -d cuda -o /my/output/path -vv`` .. include:: links.rst diff --git a/requirements.txt b/requirements.txt index 4d442928ae11c6f82d61ee59945e7bfa38966a01..262a99b9420fe095e958bb0b9ec8aa2bb8ab2ace 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,6 @@ setuptools numpy bob.extension -bob.db.drive -bob.db.stare -bob.db.chasedb1 -bob.db.hrf -bob.db.drionsdb -bob.db.rimoner3 -bob.db.drishtigs1 -bob.db.refuge -bob.db.iostar torch torchvision pandas diff --git a/setup.py b/setup.py index d5fadd7a2b63e6c1d295a2418c51807adcddbf9f..2cc4f344b0380941d52b36d37f2f638c2cec4b63 100644 --- a/setup.py +++ b/setup.py @@ -65,6 +65,7 @@ setup( 'M2UNetSSL = bob.ip.binseg.configs.models.m2unetssl', 'UNet = bob.ip.binseg.configs.models.unet', 'ResUNet = bob.ip.binseg.configs.models.resunet', + 'IMAGEFOLDER = bob.ip.binseg.configs.datasets.imagefolder', 'CHASEDB1 = bob.ip.binseg.configs.datasets.chasedb1', 'CHASEDB1TEST = bob.ip.binseg.configs.datasets.chasedb1test', 'COVD-DRIVE = bob.ip.binseg.configs.datasets.starechasedb1iostarhrf544',