afiliot's picture
Upload 4 files
377f9d4
raw
history blame
1.23 kB
# Copyright (c) Owkin, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# Copyright (c) Owkin, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from typing import Tuple
import numpy as np
import torch
import datasets
class SlideFeaturesDataset:
"""Slide features dataset."""
def __init__(self, *args, **kwargs):
self.hf_dataset = datasets.oad_dataset(*args, **kwargs).with_format("torch")
def __getitem__(self, item: np.int64) -> Tuple[torch.Tensor, torch.Tensor]:
"""
Parameters
----------
item: np.int64
Index of item, will be converted to int.
Returns
-------
Tuple[torch.Tensor, torch.Tensor]
(1000, 768), ()
"""
return (
self.hf_dataset[int(item)]["features"],
self.hf_dataset[int(item)]["label"].unsqueeze(0).float()
)
def __len__(self) -> int:
return len(self.hf_dataset)
@property
def labels(self):
return self.hf_dataset["label"]