当前位置:   article > 正文

python sample函数取样_Pytorch各种取样器sample

tensor sample函数

测试了pytorch的三种取样器用法。

一:概念

Sample:

取样器是在某一个数据集合上,按照某种策略进行取样。常见的策略包括顺序取样,随机取样(个样本等概率),随机取样(赋予个样本不同的概率)。以上三个策略都有放回和不放回两种方式。

TensorDataset:

对多个数据列表进行简单包装。就是用一个更大的list将多个不同类型的list数据进行简单包装。代码如下:

class TensorDataset(Dataset):

r"""Dataset wrapping tensors.

Each sample will be retrieved by indexing tensors along the first dimension.

Arguments:

*tensors (Tensor): tensors that have the same size of the first dimension.

"""

def __init__(self, *tensors):

assert all(tensors[0].size(0) == tensor.size(0) for tensor in tensors)

self.tensors = tensors

def __getitem__(self, index):

return tuple(tensor[index] for tensor in self.tensors)

def __len__(self):

return self.tensors[0].size(0)

二参数

1.SequentialSampler()

顺序采样&

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/57509
推荐阅读
相关标签
  

闽ICP备14008679号