|
5 | 5 |
|
6 | 6 |
|
7 | 7 | 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 | + """ |
9 | 36 |
|
10 | 37 | def __init__( |
11 | 38 | self, |
@@ -39,18 +66,45 @@ def __init__( |
39 | 66 | ) |
40 | 67 |
|
41 | 68 | 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 | + """ |
43 | 80 | return int(np.floor(len(self.indices) / self.batch_size)) |
44 | 81 |
|
45 | 82 | 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 | + """ |
47 | 90 | if self.random_seed is not None: |
48 | 91 | np.random.seed(self.random_seed) |
49 | 92 | np.random.shuffle(self.indices) |
50 | 93 |
|
51 | 94 | 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. |
53 | 102 |
|
| 103 | + Returns: |
| 104 | + -------- |
| 105 | + tuple |
| 106 | + A tuple containing the input data as features and the corresponding labels. |
| 107 | + """ |
54 | 108 | # Generate indices of the batch |
55 | 109 | batch_indices = self.indices[index * self.batch_size : (index + 1) * self.batch_size] |
56 | 110 | if self.DLDataReader.mode == "mono": |
|
0 commit comments