我遇到了一个问题!
最近,我遇到一个问题的I/O问题。 目标和输入数据储存与h5py文件。 每个目标的文件是 2.6GB 虽然每个文件输入是 10.2GB. 我有5输入数据集和5个目标的数据集。
我创建了一个自定义功能的数据集每个h5py文件,然后使用 数据。ConcatDataset 类链接所有数据集。 该数据集定义功能是:
class MydataSet(Dataset):
def __init__(self, indx=1, root_path='./xxx', tar_size=128, data_aug=True, train=True):
self.train = train
if self.train:
self.in_file = pth.join(root_path, 'train', 'train_noisy_%d.h5' % indx)
self.tar_file = pth.join(root_path, 'train', 'train_clean_%d.h5' % indx)
else:
self.in_file = pth.join(root_path, 'test', 'test_noisy.h5')
self.tar_file = pth.join(root_path, 'test', 'test_clean.h5')
self.h5f_n = h5py.File(self.in_file, 'r', driver='core')
self.h5f_c = h5py.File(self.tar_file, 'r')
self.keys_n = list(self.h5f_n.keys())
self.keys_c = list(self.h5f_c.keys())
# h5f_n.close()
# h5f_c.close()
self.tar_size = tar_size
self.data_aug = data_aug
def __len__(self):
return len(self.keys_n)
def __del__(self):
self.h5f_n.close()
self.h5f_c.close()
def __getitem__(self, index):
keyn = self.keys_n[index]
keyc = self.keys_c[index]
datan = np.array(self.h5f_n[keyn])
datac = np.array(self.h5f_c[keyc])
datan_tensor = torch.from_numpy(datan).unsqueeze(0)
datac_tensor = torch.from_numpy(datac)
if self.data_aug and np.random.randint(2, size=1)[0] == 1: # horizontal flip
datan_tensor = torch.flip(datan_tensor,dims=[2]) # c h w
datac_tensor = torch.flip(datac_tensor,dims=[2])
然后我用 dataset_train = data.ConcatDataset([MydataSet(indx=index, train=True) for index in range(1, 6)])
培训。 当时只有2-3h5py文件的使用,I/O速度是正常的,一切顺利的权利。 然而,在5个文件使用的培训速度逐渐减少(5次迭代/s1迭代/s)。 我改变num_worker和问题仍然存在。
任何人都可以给我一个解决方案? 我应该合并几个h5py文件纳入一个更大的? 或其他的方法吗? 在此先感谢!