1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Pytorch】RuntimeError: Expected a 'cuda' device type for generator but found 'cpu'【Dataloader・データローダー】

Posted at

ある日こんなエラーが

epoch: 1
Traceback (most recent call last):
  File "train.py", line 168, in <module>
    main()
  File "train.py", line 77, in main
    train_loss = train(
  File "train.py", line 115, in train
    for data, label, mask in dataset:
  File "/home/ubuntu/.pyenv/versions/3.8.8/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in __next__
    data = self._next_data()
  File "/home/ubuntu/.pyenv/versions/3.8.8/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 560, in _next_data
    index = self._next_index()  # may raise StopIteration
  File "/home/ubuntu/.pyenv/versions/3.8.8/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 512, in _next_index
    return next(self._sampler_iter)  # may raise StopIteration
  File "/home/ubuntu/.pyenv/versions/3.8.8/lib/python3.8/site-packages/torch/utils/data/sampler.py", line 226, in __iter__
    for idx in self.sampler:
  File "/home/ubuntu/.pyenv/versions/3.8.8/lib/python3.8/site-packages/torch/utils/data/sampler.py", line 124, in __iter__
    yield from torch.randperm(n, generator=generator).tolist()
RuntimeError: Expected a 'cuda' device type for generator but found 'cpu'

通常、ロスなどを取るときなどに、片方はGPUで片方がCPUだと計算できないよ、というものが、なんと学習する前のデータロードするタイミングで...知らんわ笑

調べてみるとどうやら、

    torch.set_default_tensor_type("torch.cuda.FloatTensor")

こいつが悪さをしていたらしい。というわけでコメントアウトすればとりあえず動いた

バージョン
Pytorch 1.9.1

参考
https://github.com/dbolya/yolact/issues/664

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?