Pytorch:RuntimeError: randperm is only implemented for CPU

Pytorch iter问题

/anaconda3/lib/python3.6/site-packages/torch/utils/data/sampler.py文件中的__iter__函数改为如下形式:

class RandomSampler(Sampler):
    r"""Samples elements randomly, without replacement.

    Arguments:
        data_source (Dataset): dataset to sample from
    """

    def __init__(self, data_source):
        self.data_source = data_source
        #print('torch.device:',torch.device)
    def __iter__(self):
        cpu = torch.device('cpu',0)
        return iter(torch.randperm(len(self.data_source),device=cpu).tolist())

    def __len__(self):
        return len(self.data_source)

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 1970-01-01
  • 2021-06-01
  • 2022-02-28
  • 2021-11-02
  • 2021-05-22
猜你喜欢
  • 2021-08-01
  • 2022-12-23
  • 2021-11-22
  • 2021-04-09
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案