data_block api:show_batch导致CUDA未知错误

问题描述 投票:0回答:1

我是新手,然后尝试学习fastai数据块api

这里是错误,代码与教程完全相同:

coco = untar_data(URLs.COCO_TINY)
path=coco/'train.json'
images, lbl_bbox = get_annotations(coco/'train.json')
img2bbox = dict(zip(images, lbl_bbox))
get_y_func = lambda o:img2bbox[o.name]


data = (ObjectItemList.from_folder(coco)
    .split_by_rand_pct()
    .label_from_func(get_y_func)
    .transform(get_transforms(), tfm_y=True)
    .databunch(bs=1, num_workers=0,collate_fn=bb_pad_collate))



data.show_batch(rows=2, ds_type=DatasetType.Valid, figsize=(6,6))

然后错误是:

  File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\IPython\core\interactiveshell.py", line 
 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-7-25e60680c0ba>", line 15, in <module>
   data.show_batch(rows=2, ds_type=DatasetType.Valid, figsize=(6,6))
File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\fastai\basic_data.py", line 185, in show_batch
   x,y = self.one_batch(ds_type, True, True)
File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\fastai\basic_data.py", line 168, in one_batch
  try:     x,y = next(iter(dl))
File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\fastai\basic_data.py", line 75, in __iter__
  for b in self.dl: yield self.proc_batch(b)
File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\torch\utils\data\dataloader.py", line 348,__next__
  data = _utils.pin_memory.pin_memory(data)
File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\torch\utils\data\_utils\pin_memory.py", line 
  55, in pin_memory
  return [pin_memory(sample) for sample in data]
File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\torch\utils\data\_utils\pin_memory.py", line 
  55, in <listcomp>
  return [pin_memory(sample) for sample in data]
File "D:\Anaconda3\envs\pytorch-gpu\lib\site-packages\torch\utils\data\_utils\pin_memory.py", line 
  47, in pin_memory
return data.pin_memory()
RuntimeError: CUDA error: unknown error

关于此错误,Internet上的所有论坛都在设置DataLoader的参数,但此处似乎不使用它

我将如何处理?

pytorch fast-ai
1个回答
0
投票

我也收到此错误。我通过在笔记本头中编辑以下两行来修复它:

import os
os.environ['CUDA_VISIBLE_DEVICES']='2'
热门问题
推荐问题
最新问题