Skip to content

Commit 3dad0f9

Browse files
committed
polish docstring
1 parent 2c0419c commit 3dad0f9

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

dl1_data_handler/loader.py

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,34 @@
55

66

77
class DLDataLoader(Sequence):
8-
"Generates batches for Keras application"
8+
"""
9+
Generates batches for Keras application.
10+
11+
DLDataLoader is a data loader class that inherits from ``~keras.utils.Sequence``.
12+
It is designed to handle and load data for deep learning models in a batch-wise manner.
13+
14+
Attributes:
15+
-----------
16+
data_reader : DLDataReader
17+
An instance of DLDataReader to read the input data.
18+
indices : list
19+
List of indices to specify the data to be loaded.
20+
tasks : list
21+
List of tasks to be performed on the data to properly set up the labels.
22+
batch_size : int
23+
Size of the batch to load the data.
24+
random_seed : int, optional
25+
Whether to shuffle the data after each epoch with a provided random seed.
26+
27+
Methods:
28+
--------
29+
__len__():
30+
Returns the number of batches per epoch.
31+
__getitem__(index):
32+
Generates one batch of data.
33+
on_epoch_end():
34+
Updates indices after each epoch if random seed is provided.
35+
"""
936

1037
def __init__(
1138
self,
@@ -39,18 +66,45 @@ def __init__(
3966
)
4067

4168
def __len__(self):
42-
"Denotes the number of batches per epoch"
69+
"""
70+
Returns the number of batches per epoch.
71+
72+
This method calculates the number of batches required to cover the entire dataset
73+
based on the batch size.
74+
75+
Returns:
76+
--------
77+
int
78+
Number of batches per epoch.
79+
"""
4380
return int(np.floor(len(self.indices) / self.batch_size))
4481

4582
def on_epoch_end(self):
46-
"Updates indexes after each epoch if random seed is set"
83+
"""
84+
Updates indices after each epoch. If a random seed is provided, the indices are shuffled.
85+
86+
This method is called at the end of each epoch to ensure that the data is shuffled
87+
if the shuffle attribute is set to True. This helps in improving the training process
88+
by providing the model with a different order of data in each epoch.
89+
"""
4790
if self.random_seed is not None:
4891
np.random.seed(self.random_seed)
4992
np.random.shuffle(self.indices)
5093

5194
def __getitem__(self, index):
52-
"Generate one batch of data"
95+
"""
96+
Generates one batch of data.
97+
98+
Parameters:
99+
-----------
100+
index : int
101+
Index of the batch to generate.
53102
103+
Returns:
104+
--------
105+
tuple
106+
A tuple containing the input data as features and the corresponding labels.
107+
"""
54108
# Generate indices of the batch
55109
batch_indices = self.indices[index * self.batch_size : (index + 1) * self.batch_size]
56110
if self.DLDataReader.mode == "mono":

0 commit comments

Comments
 (0)