You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] add ImageFolder/DatasetFolder: incremental index caching to avoid full filesystem re-scans #9659
ImageFolder and DatasetFolder do a full recursive scan of the directory
(os.walk / os.scandir) every time they're instantiated, even if nothing on
disk has changed. For large datasets, or anything on a network mount, this
can take minutes — every single run.
This hurts most with: restarting training scripts during debugging, jobs
that get preempted and restarted on clusters, distributed training where
every rank/worker rescans the same unchanged tree, and datasets that grow
over time with no way to update the index without a full rescan.
An opt-in cache_index flag with an incremental mode that only rescans
folders that actually changed.
First run scans normally and writes the index to cache_path. Later runs
check folder mtimes against the cache, rescan only what changed, and merge
the result — no full rescan unless nearly everything changed.
Alternatives considered
Leaving this to user-built wrappers (already common, but inconsistent and
often buggy), caching by default (risky — could silently hide stale data),
and a heavier format like LMDB/SQLite (more than this needs).
Pure Python change in torchvision/datasets/folder.py, fully backward
compatible.
The idea of adding an incremental index caching feature sounds useful, especially for large datasets or network mounts. It could really help with reducing unnecessary rescans during debugging or distributed training.
Hi @MBUYt0n, checking in to see if you've started working on a draft PR for this! I'd be happy to collaborate, help write unit tests, or test the implementation once it's ready.
Also @Kaustubh1235, totally agree—incremental index caching would be a huge performance win for large datasets and network mounts."
Activity
MBUYt0n commentedon Sep 16, 2026
Hi, I'm currently looking into this issue and will try raising a PR on it soon!
Kaustubh1235 commentedon Sep 19, 2026
The idea of adding an incremental index caching feature sounds useful, especially for large datasets or network mounts. It could really help with reducing unnecessary rescans during debugging or distributed training.
powerofaisinstudy-debug commentedon Sep 20, 2026
Hi @MBUYt0n, checking in to see if you've started working on a draft PR for this! I'd be happy to collaborate, help write unit tests, or test the implementation once it's ready.
Also @Kaustubh1235, totally agree—incremental index caching would be a huge performance win for large datasets and network mounts."
MBUYt0n commentedon Sep 23, 2026
I'll raise the PR once the issue is assigned to me!