MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __init__

Method __init__

monai/data/samplers.py:43–61  ·  view source on GitHub ↗
(
        self,
        dataset: Dataset,
        even_divisible: bool = True,
        num_replicas: int | None = None,
        rank: int | None = None,
        shuffle: bool = True,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

41 """
42
43 def __init__(
44 self,
45 dataset: Dataset,
46 even_divisible: bool = True,
47 num_replicas: int | None = None,
48 rank: int | None = None,
49 shuffle: bool = True,
50 **kwargs,
51 ):
52 super().__init__(dataset=dataset, num_replicas=num_replicas, rank=rank, shuffle=shuffle, **kwargs)
53
54 if not even_divisible:
55 data_len = len(dataset) # type: ignore
56 if data_len < self.num_replicas:
57 raise ValueError("the dataset length is less than the number of participating ranks.")
58 extra_size = self.total_size - data_len
59 if self.rank + extra_size >= self.num_replicas:
60 self.num_samples -= 1
61 self.total_size = data_len
62
63
64class DistributedWeightedRandomSampler(DistributedSampler):

Callers 1

__init__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected