Skip to content

Commit

Permalink
Rename num_calls to num_samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinnee committed Mar 9, 2022
1 parent eb95903 commit 93bf517
Show file tree
Hide file tree
Showing 28 changed files with 105 additions and 104 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ I2K 2022 *“developing open source image analysis platforms/tools”*
- [x] re-ordering channels
np.ascontiguousarray, 'C' order, arr[..., (2, 1, 0)]
- [x] random sampling, shuffle in BatchDataLoader
- [ ] `indices` to index in hard-coded way for those that have no training/test split
- [ ] Metrics for benchmarking (StarDist has done a great job, their license is BSD-3)
- [ ] (maybe nope) Download scripts

Expand All @@ -51,8 +52,8 @@ I2K 2022 *“developing open source image analysis platforms/tools”*
- [x] BBBC041
- [x] consistent `root_dir`. Now it is a mess. We want something described in the
`docs/user_guides/basic0_prepare_datasets.rst`.
- [x] substitute `num_calls` with `num_samples`? (I think samples sound right)
- [ ] number of images, including test sets
- [ ] substitute `num_calls` with `num_samples`? (I think samples sound right)
- [ ] Load all anno types, if there are more than one (e.g. BBBC007)

### Others
Expand Down
30 changes: 15 additions & 15 deletions bioimageloader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Dataset(DatasetInterface):
root_dir
output
transforms
num_calls
num_samples
grayscale : optional
grayscale_mode : optional
num_channels : optional
Expand All @@ -106,9 +106,9 @@ def __repr__(self):
return self.acronym

def __len__(self):
"""Length of dataset. Can be overwritten with ``num_calls``"""
if self.num_calls is not None:
return self.num_calls
"""Length of dataset. Can be overwritten with ``num_samples``"""
if self.num_samples is not None:
return self.num_samples
return len(self.file_list)

def __iter__(self):
Expand Down Expand Up @@ -136,10 +136,10 @@ def transforms(self) -> Optional[albumentations.Compose]:
return None

@property
def num_calls(self) -> Optional[int]:
def num_samples(self) -> Optional[int]:
"""Number of calls that will override __len__"""
if hasattr(self, '_num_calls'):
return getattr(self, '_num_calls')
if hasattr(self, '_num_samples'):
return getattr(self, '_num_samples')
return None

@property
Expand Down Expand Up @@ -189,15 +189,15 @@ def __getitem__(self, ind: int) -> Dict[str, np.ndarray]:
Other Parameters
----------------
self._transforms
self._num_calls
self._num_samples
self._grayscale
self._grayscale_mode
self._num_channels
"""
# Randomize `ind` when `num_calls` set
if self.num_calls is not None:
if ind >= self.num_calls:
# Randomize `ind` when `num_samples` set
if self.num_samples is not None:
if ind >= self.num_samples:
raise IndexError('list index out of range')
ind_max = len(self.file_list)
ind = random.randrange(0, ind_max)
Expand Down Expand Up @@ -342,15 +342,15 @@ def __getitem__(self, ind: int) -> Dict[str, np.ndarray]:
Other Parameters
----------------
self._transforms
self._num_calls
self._num_samples
self._grayscale
self._grayscale_mode
self._num_channels
"""
# Randomize `ind` when `num_calls` set
if self.num_calls is not None:
if ind >= self.num_calls:
# Randomize `ind` when `num_samples` set
if self.num_samples is not None:
if ind >= self.num_samples:
raise IndexError('list index out of range')
ind_max = len(self.file_list)
if (self.output != 'image') and (self.anno_dict is not None):
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc002.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BBBC002(Dataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
Expand Down Expand Up @@ -55,12 +55,12 @@ def __init__(
root_dir: str,
*,
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
**kwargs
):
self._root_dir = root_dir
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples

def get_image(self, p: Path) -> np.ndarray:
img = tifffile.imread(p)
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc006.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BBBC006(MaskDataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(
*,
output: str = 'both',
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -92,7 +92,7 @@ def __init__(
self._root_dir = root_dir
self._output = output
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# specific to this dataset
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc007.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BBBC007(MaskDataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(
*,
output: str = 'both',
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -87,7 +87,7 @@ def __init__(
self._root_dir = root_dir
self._output = output
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
self.image_ch = image_ch
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc008.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BBBC008(MaskDataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when `transforms` is set. Define the total length of the dataset.
If it is set, it overrides ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(
*,
output: str = 'both',
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -85,7 +85,7 @@ def __init__(
self._root_dir = root_dir
self._output = output
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# specific to this dataset
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc013.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BBBC013(Dataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(
root_dir: str,
*,
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -71,7 +71,7 @@ def __init__(
):
self._root_dir = root_dir
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# specific to this dataset
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc014.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BBBC014(Dataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(
root_dir: str,
*,
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -80,7 +80,7 @@ def __init__(
):
self._root_dir = root_dir
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# specific to this dataset
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc015.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BBBC015(Dataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(
root_dir: str,
*,
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -79,7 +79,7 @@ def __init__(
):
self._root_dir = root_dir
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# specific to this dataset
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc016.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BBBC016(Dataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(
root_dir: str,
*,
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -74,7 +74,7 @@ def __init__(
):
self._root_dir = root_dir
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# specific to this dataset
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc018.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BBBC018(MaskDataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(
*,
output: str = 'both',
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -113,7 +113,7 @@ def __init__(
self._root_dir = root_dir
self._output = output
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# self.image_ch = image_ch
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc020.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BBBC020(MaskDataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -93,7 +93,7 @@ def __init__(
*,
output: str = 'both',
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# specific to this dataset
Expand All @@ -104,7 +104,7 @@ def __init__(
self._root_dir = root_dir
self._output = output
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
# specific to this dataset
Expand Down
6 changes: 3 additions & 3 deletions bioimageloader/collections/_bbbc021.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BBBC021(Dataset):
transforms : albumentations.Compose, optional
An instance of Compose (albumentations pkg) that defines augmentation in
sequence.
num_calls : int, optional
num_samples : int, optional
Useful when ``transforms`` is set. Define the total length of the
dataset. If it is set, it overwrites ``__len__``.
grayscale : bool, default: False
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(
root_dir: str,
*,
transforms: Optional[albumentations.Compose] = None,
num_calls: Optional[int] = None,
num_samples: Optional[int] = None,
grayscale: bool = False,
grayscale_mode: Union[str, Sequence[float]] = 'equal',
# # specific to this dataset
Expand All @@ -81,7 +81,7 @@ def __init__(
):
self._root_dir = root_dir
self._transforms = transforms
self._num_calls = num_calls
self._num_samples = num_samples
self._grayscale = grayscale
self._grayscale_mode = grayscale_mode
self.image_ch = image_ch
Expand Down

0 comments on commit 93bf517

Please sign in to comment.