gpt4 book ai didi

python - DataLoader worker 意外退出(pid(s) 48817、48818)

转载 作者:行者123 更新时间:2023-12-02 16:07:41 28 4
gpt4 key购买 nike

运行我的代码时,我收到此错误消息“RuntimeError: DataLoader worker (pid(s) 48817, 48818) exited unexpectedly” 我完全不确定从哪里开始解决这个问题。任何指导都将不胜感激。下面发布代码和回溯

batch_size = 128
image_size = (64,64)
stats = (0.5, 0.5, 0.5), (0.5, 0.5, 0.5)

transform_ds = transforms.Compose([transforms.Resize(image_size),
# transforms.RandomCrop(32, padding=2),
# transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize(*stats)
])

train_ds = facesDataset(csv_file = 'imagesdataset.csv', root_dir = 'images',
transform = transform_ds)

train_dl = DataLoader(train_ds, batch_size, shuffle=True, num_workers=3, pin_memory=True)
print(len(train_ds))

def denorm(img_tensors):
return img_tensors * stats[1][0] + stats[0][0]

def show_images(img, nmax=64):
fig, ax = plt.subplots(figsize=(8, 8))
ax.set_xticks([]); ax.set_yticks([])
ax.imshow(make_grid(denorm(img.detach()[:nmax]), nrow=8).permute(1, 2, 0))

def show_batch(dl, nmax=64):
for img, _ in dl:
show_images(img, nmax)
break

show_batch(train_dl)

回溯

Traceback (most recent call last):
File "/Users/___/Desktop/stylegan/stylegan.py", line 52, in <module>
show_batch(train_dl)
File "/Users/___/Desktop/stylegan/stylegan.py", line 48, in show_batch
for img, _ in dl:
File "/Users/___/opt/anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in __next__
data = self._next_data()
File "/Users/___/opt/anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1186, in _next_data
idx, data = self._get_data()
File "/Users/___/opt/anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1152, in _get_data
success, data = self._try_get_data()
File "/Users/___/opt/anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1003, in _try_get_data
raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str)) from e
RuntimeError: DataLoader worker (pid(s) 48817, 48818) exited unexpectedly

最佳答案

原因之一可能是使用多处理 加载数据。据我所知,在 Windows 中,如果您不将 num_workers 设置为 0 ,则会出现错误。所以我建议您尝试不使用 num_workers(因为默认情况下,它是 0)或直接设置它 num_workers=0

train_dl = DataLoader(train_ds, batch_size, shuffle=True, num_workers=0, pin_memory=True)

关于python - DataLoader worker 意外退出(pid(s) 48817、48818),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68931909/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com