ImageFolder dataset: "too many open files" error
Open
@fmassa is already working on this.
Since Aug 13, 2018.
module: datasets
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
Hi,
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.