-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added missing docstrings & formatting
- Loading branch information
Showing
8 changed files
with
59 additions
and
30 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
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,6 +1,6 @@ | ||
"""Data samplers API.""" | ||
|
||
from eva.core.data.samplers.sampler import Sampler, SamplerWithDataSource | ||
from eva.core.data.samplers.random import RandomSampler | ||
from eva.core.data.samplers.sampler import Sampler, SamplerWithDataSource | ||
|
||
__all__ = ["Sampler", "RandomSampler"] | ||
__all__ = ["Sampler", "SamplerWithDataSource", "RandomSampler"] |
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,31 +1,40 @@ | ||
"""Random sampler for data loading.""" | ||
|
||
from eva.core.data.samplers.sampler import SamplerWithDataSource | ||
from eva.core.data import datasets | ||
from typing import Optional | ||
|
||
from torch.utils import data | ||
from typing_extensions import override | ||
|
||
from eva.core.data import datasets | ||
from eva.core.data.samplers.sampler import SamplerWithDataSource | ||
|
||
class RandomSampler(data.RandomSampler, SamplerWithDataSource[int]): | ||
r"""Samples elements randomly. If without replacement, then sample from a shuffled dataset. | ||
If with replacement, then user can specify :attr:`num_samples` to draw. | ||
|
||
Args: | ||
data_source (Dataset): dataset to sample from | ||
replacement (bool): samples are drawn on-demand with replacement if ``True``, default=``False`` | ||
num_samples (int): number of samples to draw, default=`len(dataset)`. | ||
generator (Generator): Generator used in sampling. | ||
""" | ||
class RandomSampler(data.RandomSampler, SamplerWithDataSource[int]): | ||
"""Samples elements randomly.""" | ||
|
||
data_source: datasets.MapDataset # type: ignore | ||
replacement: bool | ||
|
||
def __init__(self, replacement: bool = False, num_samples: Optional[int] = None, generator=None) -> None: | ||
def __init__( | ||
self, replacement: bool = False, num_samples: Optional[int] = None, generator=None | ||
) -> None: | ||
"""Initializes the random sampler. | ||
Args: | ||
data_source: dataset to sample from | ||
replacement: samples are drawn on-demand with replacement if ``True``, default=``False`` | ||
num_samples: number of samples to draw, default=`len(dataset)`. | ||
generator: Generator used in sampling. | ||
""" | ||
self.replacement = replacement | ||
self._num_samples = num_samples | ||
self.generator = generator | ||
|
||
@override | ||
def set_dataset(self, data_source: datasets.MapDataset) -> None: | ||
super().__init__(data_source, replacement=self.replacement, num_samples=self.num_samples, generator=self.generator) | ||
super().__init__( | ||
data_source, | ||
replacement=self.replacement, | ||
num_samples=self.num_samples, | ||
generator=self.generator, | ||
) |
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 |
---|---|---|
|
@@ -23,4 +23,4 @@ def filename(self, index: int) -> str: | |
Returns: | ||
The filename of the `index`'th data sample. | ||
""" | ||
""" |