ImageFolder dataset: "too many open files" error
See original GitHub issueHi,
I am using ImageFolder dataset to train on imagenet.
I repeatedly get “too many open files” OSError after training for several hours.
I suspect the issue comes from [here][1]:
def pil_loader(path):
# open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
with open(path, 'rb') as f:
img = Image.open(f)
return img.convert('RGB') # <--
The return is inside with ... clause, thus (I suspect) the file handle f is not closed properly when the function returns.
Shouldn’t the function be
def pil_loader(path):
# open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
with open(path, 'rb') as f:
img = Image.open(f)
return img.convert('RGB') # <-- not indented
Thanks, -Shai [1]: https://github.com/pytorch/vision/blob/master/torchvision/datasets/folder.py#L156
cc @pmeier
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
pytorch Dataloader error "Too many open files" when yielding ...
I'm trying to implement a custom IterableDataset in which I read words from a file, get theirs unique id, gather them and return...
Read more >Too many open files when using dataLoader - PyTorch Forums
Hi, When I use the data loader, I have met the following error: Too many open files. In my implementation of the Dataset, ......
Read more >T-202/github-issues · Datasets at Hugging Face
Describe the bug Cannot load the dataset conll2012_ontonotesv5 ## Steps to reproduce ... in `Image.decode_example` to avoid the `Too many open files` error....
Read more >Taking Datasets, DataLoaders, and PyTorch's New DataPipes ...
We define a Dataset instance how the data files are opened, ... Also, the PyTorch team aims to keep the original Dataset and...
Read more >PyTorch ImageFolder for Training CNN Models - DebuggerCafe
DatasetFolder class. So, we can override the classes to create custom datasets as well. ... If you observe closely, this is how many...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@shaibagon I tested the following and no error found:
@vfdev-5 I am sorry, but because of the remote environment I am working at it is very difficult to provide additional information. I am also suspecting I have not located to problem correctly.
Bottom line:
running for long time (day+) using
ImageFolderdata results with OSError “too many open files”.I will do my best to shed more light on this issue. meanwhile, I don’t think there’s much to do.
Other people who stumble upon this error - please try and provide more information.