-
Notifications
You must be signed in to change notification settings - Fork 21.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webdataset prototype - LoadFilesFromDiskIterableDataset (#48955)
Summary: Pull Request resolved: #48955 Test Plan: Imported from OSS Reviewed By: izdeby Differential Revision: D25541393 Pulled By: glaringlee fbshipit-source-id: dea6ad64a7ba40abe45612d99f078b14d1da8bbf
- Loading branch information
1 parent
6786b2b
commit 001ff3a
Showing
4 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .listdirfilesdataset import ListDirFilesIterableDataset | ||
from .loadfilesfromdiskdataset import LoadFilesFromDiskIterableDataset | ||
|
||
__all__ = ['ListDirFilesIterableDataset'] | ||
__all__ = ['ListDirFilesIterableDataset', 'LoadFilesFromDiskIterableDataset'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from torch.utils.data.dataset import IterableDataset | ||
from torch.utils.data.datasets.common import get_file_binaries_from_pathnames | ||
|
||
from typing import Iterable, Iterator | ||
|
||
class LoadFilesFromDiskIterableDataset(IterableDataset): | ||
r""" :class:`LoadFilesFromDiskIterableDataset`. | ||
IterableDataset to load file binary streams from given pathnames, | ||
yield pathname and binary stream in a tuple. | ||
args: | ||
dataset: Iterable dataset that provides pathnames | ||
length: a nominal length of the dataset | ||
""" | ||
|
||
def __init__( | ||
self, | ||
dataset : Iterable, | ||
length : int = -1): | ||
super().__init__() | ||
self.dataset : Iterable = dataset | ||
self.length : int = length | ||
|
||
def __iter__(self) -> Iterator[tuple] : | ||
yield from get_file_binaries_from_pathnames(self.dataset) | ||
|
||
def __len__(self): | ||
if self.length == -1: | ||
raise NotImplementedError | ||
return self.length |