Diff of /datasets/basic_dataset.py [000000] .. [03464c]

Switch to unified view

a b/datasets/basic_dataset.py
1
"""
2
This module implements an abstract base class for datasets. Other datasets can be created from this base class.
3
"""
4
import torch.utils.data as data
5
from abc import ABC, abstractmethod
6
7
8
class BasicDataset(data.Dataset, ABC):
9
    """
10
    This class is an abstract base class for datasets.
11
    To create a subclass, you need to implement the following three functions:
12
    -- <__init__>:                      initialize the class, first call BasicDataset.__init__(self, param).
13
    -- <__len__>:                       return the size of dataset.
14
    -- <__getitem__>:                   get a data point.
15
    """
16
17
    def __init__(self, param):
18
        """
19
        Initialize the class, save the parameters in the class
20
        """
21
        self.param = param
22
        self.sample_list = None
23
24
    @abstractmethod
25
    def __len__(self):
26
        """Return the total number of samples in the dataset."""
27
        return 0
28
29
    @abstractmethod
30
    def __getitem__(self, index):
31
        """
32
        Return a data point and its metadata information.
33
        Parameters:
34
            index - - a integer for data indexing
35
        Returns:
36
            a dictionary of data with their names. It usually contains the data itself and its metadata information.
37
        """
38
        pass