當前位置: 首頁>>代碼示例>>Python>>正文


Python sampler.Sampler方法代碼示例

本文整理匯總了Python中torch.utils.data.sampler.Sampler方法的典型用法代碼示例。如果您正苦於以下問題:Python sampler.Sampler方法的具體用法?Python sampler.Sampler怎麽用?Python sampler.Sampler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.utils.data.sampler的用法示例。


在下文中一共展示了sampler.Sampler方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from torch.utils.data import sampler [as 別名]
# 或者: from torch.utils.data.sampler import Sampler [as 別名]
def __init__(self, sampler, group_ids, batch_size):
        """
        Args:
            sampler (Sampler): Base sampler.
            group_ids (list[int]): If the sampler produces indices in range [0, N),
                `group_ids` must be a list of `N` ints which contains the group id of each sample.
                The group ids must be a set of integers in the range [0, num_groups).
            batch_size (int): Size of mini-batch.
        """
        if not isinstance(sampler, Sampler):
            raise ValueError(
                "sampler should be an instance of "
                "torch.utils.data.Sampler, but got sampler={}".format(sampler)
            )
        self.sampler = sampler
        self.group_ids = np.asarray(group_ids)
        assert self.group_ids.ndim == 1
        self.batch_size = batch_size
        groups = np.unique(self.group_ids).tolist()

        # buffer the indices of each group until batch size is reached
        self.buffer_per_group = {k: [] for k in groups} 
開發者ID:facebookresearch,項目名稱:detectron2,代碼行數:24,代碼來源:grouped_batch_sampler.py

示例2: __init__

# 需要導入模塊: from torch.utils.data import sampler [as 別名]
# 或者: from torch.utils.data.sampler import Sampler [as 別名]
def __init__(self, keys, executed_iterations,
                 batch_size, sequence_size, sequence_stride, drop_last=True):
        sampler = PreSplittedSampler(keys, executed_iterations)

        if not isinstance(sampler, Sampler):
            raise ValueError("sampler should be an instance of "
                             "torch.utils.data.Sampler, but got sampler={}"
                             .format(sampler))
        if not isinstance(sequence_size, int) or isinstance(sequence_size, bool) or \
                sequence_size <= 0:
            raise ValueError("batch_size should be a positive integeral value, "
                             "but got batch_size={}".format(sequence_size))
        if not isinstance(drop_last, bool):
            raise ValueError("drop_last should be a boolean value, but got "
                             "drop_last={}".format(drop_last))
        self.sampler = sampler
        self.sequence_size = sequence_size
        self.batch_size = batch_size
        self.drop_last = drop_last
        self.sequence_stride = sequence_stride 
開發者ID:felipecode,項目名稱:coiltraine,代碼行數:22,代碼來源:coil_sampler.py

示例3: __init__

# 需要導入模塊: from torch.utils.data import sampler [as 別名]
# 或者: from torch.utils.data.sampler import Sampler [as 別名]
def __init__(
        self,
        sampler,
        num_replicas: Optional[int] = None,
        rank: Optional[int] = None,
        shuffle: bool = True,
    ):
        """

        Args:
            sampler: Sampler used for subsampling
            num_replicas (int, optional): Number of processes participating in
              distributed training
            rank (int, optional): Rank of the current process
              within ``num_replicas``
            shuffle (bool, optional): If true (default),
              sampler will shuffle the indices
        """
        super(DistributedSamplerWrapper, self).__init__(
            DatasetFromSampler(sampler),
            num_replicas=num_replicas,
            rank=rank,
            shuffle=shuffle,
        )
        self.sampler = sampler 
開發者ID:catalyst-team,項目名稱:catalyst,代碼行數:27,代碼來源:sampler.py

示例4: __init__

# 需要導入模塊: from torch.utils.data import sampler [as 別名]
# 或者: from torch.utils.data.sampler import Sampler [as 別名]
def __init__(self, sampler, group_ids, batch_size, drop_uneven=False):
        if not isinstance(sampler, Sampler):
            raise ValueError(
                "sampler should be an instance of "
                "torch.utils.data.Sampler, but got sampler={}".format(sampler)
            )
        self.sampler = sampler
        self.group_ids = torch.as_tensor(group_ids)
        assert self.group_ids.dim() == 1
        self.batch_size = batch_size
        self.drop_uneven = drop_uneven

        self.groups = torch.unique(self.group_ids).sort(0)[0]

        self._can_reuse_batches = False 
開發者ID:Res2Net,項目名稱:Res2Net-maskrcnn,代碼行數:17,代碼來源:grouped_batch_sampler.py

示例5: __init__

# 需要導入模塊: from torch.utils.data import sampler [as 別名]
# 或者: from torch.utils.data.sampler import Sampler [as 別名]
def __init__(self, sampler, batch_size, drop_last):
        if not isinstance(sampler, torch_sampler.Sampler):
            raise ValueError("sampler should be an instance of "
                             "torch.utils.data.Sampler, but got sampler={}"
                             .format(sampler))
        if not isinstance(batch_size, _int_classes) or isinstance(batch_size, bool) or \
                batch_size <= 0:
            raise ValueError("batch_size should be a positive integeral value, "
                             "but got batch_size={}".format(batch_size))
        if not isinstance(drop_last, bool):
            raise ValueError("drop_last should be a boolean value, but got "
                             "drop_last={}".format(drop_last))
        self.sampler = sampler
        self.batch_size = batch_size
        self.drop_last = drop_last 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:17,代碼來源:loader.py

示例6: __init__

# 需要導入模塊: from torch.utils.data import sampler [as 別名]
# 或者: from torch.utils.data.sampler import Sampler [as 別名]
def __init__(self, sampler, group_ids, batch_size):
        if not isinstance(sampler, Sampler):
            raise ValueError(
                "sampler should be an instance of " "torch.utils.data.Sampler, but got sampler={}".format(sampler)
            )
        self.sampler = sampler
        self.group_ids = group_ids
        self.batch_size = batch_size 
開發者ID:bhoov,項目名稱:exbert,代碼行數:10,代碼來源:grouped_batch_sampler.py

示例7: __init__

# 需要導入模塊: from torch.utils.data import sampler [as 別名]
# 或者: from torch.utils.data.sampler import Sampler [as 別名]
def __init__(self, sampler, group_ids, batch_size):
        if not isinstance(sampler, Sampler):
            raise ValueError(
                "sampler should be an instance of "
                "torch.utils.data.Sampler, but got sampler={}".format(sampler)
            )
        self.sampler = sampler
        self.group_ids = group_ids
        self.batch_size = batch_size 
開發者ID:monologg,項目名稱:DistilKoBERT,代碼行數:11,代碼來源:grouped_batch_sampler.py


注:本文中的torch.utils.data.sampler.Sampler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。