Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Expected a 'cuda' device type for generator but found 'cpu' #578

Open
justinge opened this issue May 28, 2022 · 2 comments
Open

Comments

@justinge
Copy link

D:\ProgramData\Anaconda3\python.exe D:/code/python/ssd.pytorch/train.py
Loading base network...
Initializing weights...
Loading the dataset...
Training SSD on: VOC0712
Using the specified args:
Namespace(basenet='vgg16_reducedfc.pth', batch_size=32, cuda=True, dataset='VOC', dataset_root='D:\code\python\ssd.pytorch\data/VOCdevkit/', gamma=0.1, lr=0.001, momentum=0.9, num_workers=4, resume=None, save_folder='weights/', start_iter=0, visdom=False, weight_decay=0.0005)
Traceback (most recent call last):
File "D:/code/python/ssd.pytorch/train.py", line 261, in
train()
File "D:/code/python/ssd.pytorch/train.py", line 150, in train
batch_iterator = iter(data_loader)
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 359, in iter
return self._get_iterator()
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 305, in _get_iterator
return _MultiProcessingDataLoaderIter(self)
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 944, in init
self._reset(loader, first_iter=True)
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 975, in _reset
self._try_put_index()
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 1209, in _try_put_index
index = self._next_index()
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 512, in _next_index
return next(self._sampler_iter) # may raise StopIteration
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\sampler.py", line 229, in iter
for idx in self.sampler:
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\sampler.py", line 126, in iter
yield from torch.randperm(n, generator=generator).tolist()
RuntimeError: Expected a 'cuda' device type for generator but found 'cpu'

@tengfei1998
Copy link

I have also encountered this problem, did you solve it please?

@wln20
Copy link

wln20 commented Nov 18, 2022

Change the data_loader definition sentence(approximately at line 145) to the following sentence :
data_loader = data.DataLoader(dataset, args.batch_size,
num_workers=args.num_workers,
shuffle=True, collate_fn=detection_collate,
pin_memory=True,
generator = torch.Generator(device='cuda'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants