여러 개의 custom data를 빠르게 batch size를 불러오게 위해 num_workers를 늘리고자 하는데 아래와 같은 에러가 발생합니다.
<코드>
class CustomDataset_data(Dataset):
def init(self):
self.x_in, self.X_in = x_in.copy(), X_in.copy()
self.xin_initi= x_in_initi.copy()
self.yin_initi = y_in_initi.copy()
self.xin_data, = x_in_data.copy()
self.yin_data = y_in_data.copy()
self.xin_random, self.Xin_random = x_in_collocation.copy(), X_in_collocation.copy()
def len(self):
return self.xout_random.shape[0]
def getitem(self, idx):
xin = torch.tensor(self.x_in[idx%x_in.shape[0]], dtype = torch.float).cuda()
Xin = torch.tensor(self.X_in[idx%x_in.shape[0]], dtype = torch.float).cuda()
xin_initi = torch.tensor(self.xin_initi[idx%x_in_initi.shape[0]], dtype = torch.float).cuda()
yin_initi = torch.tensor(self.yin_initi[idx%x_in_initi.shape[0]], dtype = torch.float).cuda()
xin__data = torch.tensor(self.xin_data[idx%x_in_data.shape[0]], dtype = torch.float).cuda()
yin__data = torch.tensor(self.yin_data[idx%x_in_data.shape[0]], dtype = torch.float).cuda()
xin_random = torch.tensor(self.xin_random[idx%x_in_collocation.shape[0]], dtype = torch.float).cuda()
Xin_random = torch.tensor(self.Xin_random[idx%X_in_collocation.shape[0]], dtype = torch.float).cuda()
xin_random_data = (xin_random, Xin_random)
xin_data = (xin__data, yin__data)
xint_data = (xin, Xin)
xin_initial_data = (xin_initial, yin_initial)
return xin_data, xin_initi_data, xin_data, xin_random_data
dataloader_data = DataLoader(CustomDataset_data(), batch_size = 1000, shuffle=True, num_workers = 2 )
<에러>
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/root/anaconda3/envs/w/lib/python3.9/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/root/anaconda3/envs/w/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
++ 혹시 dataloader 코드 부분에서 어색하거나 효율적이지 않은 부분이 있다면 지적해주세요!!