forked from activeloopai/deeplake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_dataset_iter.py
63 lines (46 loc) · 1.82 KB
/
benchmark_dataset_iter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
License:
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
"""
import torch
from hub import Dataset
from hub.utils import Timer
DATASET_NAMES = ["activeloop/mnist", "activeloop/cifar10_train"]
BATCH_SIZES = [1, 16, 128]
PREFETCH_SIZES = [1, 4, 16, 128]
def time_iter_pytorch(
dataset_name="activeloop/mnist", batch_size=1, prefetch_factor=0, process=None
):
dset = Dataset(dataset_name, cache=False, storage_cache=False, mode="r")
loader = torch.utils.data.DataLoader(
dset.to_pytorch(),
batch_size=batch_size,
prefetch_factor=prefetch_factor,
num_workers=1,
)
with Timer(
f"{dataset_name} PyTorch prefetch {prefetch_factor:03} in batches of {batch_size:03}"
):
for idx, (image, label) in enumerate(loader):
if process is not None:
process(idx, image, label)
def time_iter_tensorflow(
dataset_name="activeloop/mnist", batch_size=1, prefetch_factor=0, process=None
):
dset = Dataset(dataset_name, cache=False, storage_cache=False, mode="r")
loader = dset.to_tensorflow().batch(batch_size).prefetch(prefetch_factor)
with Timer(
f"{dataset_name} TF prefetch {prefetch_factor:03} in batches of {batch_size:03}"
):
for idx, batch in enumerate(loader):
image = batch["image"]
label = batch["label"]
if process is not None:
process(idx, image, label)
if __name__ == "__main__":
for name in DATASET_NAMES:
for size in BATCH_SIZES:
for prefetch in PREFETCH_SIZES:
time_iter_pytorch(name, size, prefetch, None)
time_iter_tensorflow(name, size, prefetch, None)