forked from activeloopai/deeplake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_torch.py
More file actions
29 lines (23 loc) · 729 Bytes
/
Copy path_torch.py
File metadata and controls
29 lines (23 loc) · 729 Bytes
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
try:
from torch.utils.data import Dataset
except ImportError:
raise ImportError(
"Torch is not installed. Please install torch to use this feature."
)
import deeplake
class TorchDataset(Dataset):
def __init__(self, ds: deeplake.Dataset, transform=None):
self.ds = ds
self.transform = transform
self.column_names = [col.name for col in ds.schema.columns]
def __len__(self):
return len(self.ds)
def __getitem__(self, idx):
sample = self.ds[idx]
if self.transform:
return self.transform(sample)
else:
out = {}
for col in self.column_names:
out[col] = sample[col]
return out