Update scripts/data.py
Browse files- scripts/data.py +5 -6
scripts/data.py
CHANGED
@@ -16,10 +16,12 @@ import torch
|
|
16 |
|
17 |
import datasets
|
18 |
|
19 |
-
class SlideFeaturesDataset:
|
20 |
"""Slide features dataset."""
|
21 |
def __init__(self, *args, **kwargs):
|
22 |
self.hf_dataset = datasets.load_dataset(*args, **kwargs).with_format("torch")
|
|
|
|
|
23 |
|
24 |
def __getitem__(self, item: np.int64) -> Tuple[torch.Tensor, torch.Tensor]:
|
25 |
"""
|
@@ -31,12 +33,9 @@ class SlideFeaturesDataset:
|
|
31 |
Returns
|
32 |
-------
|
33 |
Tuple[torch.Tensor, torch.Tensor]
|
34 |
-
(1000, 768), ()
|
35 |
"""
|
36 |
-
return (
|
37 |
-
self.hf_dataset[int(item)]["features"],
|
38 |
-
self.hf_dataset[int(item)]["label"].unsqueeze(0).float()
|
39 |
-
)
|
40 |
|
41 |
def __len__(self) -> int:
|
42 |
return len(self.hf_dataset)
|
|
|
16 |
|
17 |
import datasets
|
18 |
|
19 |
+
class SlideFeaturesDataset(torch.utils.data.Dataset):
|
20 |
"""Slide features dataset."""
|
21 |
def __init__(self, *args, **kwargs):
|
22 |
self.hf_dataset = datasets.load_dataset(*args, **kwargs).with_format("torch")
|
23 |
+
self.features = self.hf_dataset["features"]
|
24 |
+
self.labels = self.hf_dataset["label"]
|
25 |
|
26 |
def __getitem__(self, item: np.int64) -> Tuple[torch.Tensor, torch.Tensor]:
|
27 |
"""
|
|
|
33 |
Returns
|
34 |
-------
|
35 |
Tuple[torch.Tensor, torch.Tensor]
|
36 |
+
(1000, 768), (1)
|
37 |
"""
|
38 |
+
return (self.features[item], self.labels.unsqueeze(0).float())
|
|
|
|
|
|
|
39 |
|
40 |
def __len__(self) -> int:
|
41 |
return len(self.hf_dataset)
|