I wrote something follow your instruction. But it doesn’t work for me.
Here is what I do:
def _load_hdf5_file(hdf5_file):
f = h5py.File(hdf5_file, "r")
data = []
for key in f.keys():
data.append(f[key])
return tuple(data)
class HDF5Dataset(Dataset):
def __init__(self, data_files):
self.data_files = sorted(data_files)
def __getitem__(self, index):
return _load_hdf5_file(self.data_files[index])
def __len__(self):
return len(self.data_files)
train_set = HDF5Dataset(train_files) # there is only one file in train_files, i.e. train_files = ["foo_1"]
train_loader = DataLoader(dataset=train_set,
batch_size=train_batch_size,
shuffle=True,
num_workers=2)
And during iteration, I got this error:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/util.py", line 274, in _run_finalizers
File "/usr/lib/python2.7/multiprocessing/util.py", line 207, in __call__
File "/usr/lib/python2.7/shutil.py", line 239, in rmtree
File "/usr/lib/python2.7/shutil.py", line 237, in rmtree
OSError: [Errno 24] Too many open files: '/tmp/pymp-Y6oJsO'
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
File "/home/ts-yandixia01/.local/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 36, in _worker_loop
File "/usr/lib/python2.7/multiprocessing/queues.py", line 392, in put
File "/home/ts-yandixia01/.local/lib/python2.7/site-packages/torch/multiprocessing/queue.py", line 17, in send
File "/usr/lib/python2.7/pickle.py", line 224, in dump
File "/usr/lib/python2.7/pickle.py", line 286, in save
File "/usr/lib/python2.7/pickle.py", line 554, in save_tuple
File "/usr/lib/python2.7/pickle.py", line 286, in save
File "/usr/lib/python2.7/pickle.py", line 606, in save_list
File "/usr/lib/python2.7/pickle.py", line 639, in _batch_appends
File "/usr/lib/python2.7/pickle.py", line 286, in save
File "/usr/lib/python2.7/pickle.py", line 606, in save_list
File "/usr/lib/python2.7/pickle.py", line 639, in _batch_appends
File "/usr/lib/python2.7/pickle.py", line 286, in save
File "/usr/lib/python2.7/pickle.py", line 606, in save_list
File "/usr/lib/python2.7/pickle.py", line 639, in _batch_appends
File "/usr/lib/python2.7/pickle.py", line 286, in save
File "/usr/lib/python2.7/multiprocessing/forking.py", line 67, in dispatcher
File "/usr/lib/python2.7/pickle.py", line 401, in save_reduce
File "/usr/lib/python2.7/pickle.py", line 286, in save
File "/usr/lib/python2.7/pickle.py", line 554, in save_tuple
File "/usr/lib/python2.7/pickle.py", line 286, in save
File "/usr/lib/python2.7/multiprocessing/forking.py", line 66, in dispatcher
File "/home/ts-yandixia01/.local/lib/python2.7/site-packages/torch/multiprocessing/reductions.py", line 116, in reduce_storage
File "/usr/lib/python2.7/multiprocessing/reduction.py", line 145, in reduce_handle
OSError: [Errno 24] Too many open files
And the program never terminates.
Did I do anything wrong? Thanks
By the way, I don’t know if it is appropriate to ask here, how can I post python style code here like you did? Thanks.