base_datamodule
Data module for creating the data.
ETDataModule
Bases: LightningDataModule
A PyTorch Lightning data module for the eye tracking data.
Attributes:
| Name | Type | Description |
|---|---|---|
cfg |
Args
|
The configuration object. |
text_dataset_path |
Path
|
The path to the text dataset. |
train_dataset |
ETDataset
|
The training dataset. |
val_datasets |
list[ETDataset]
|
The validation datasets. |
test_datasets |
list[ETDataset]
|
The test datasets. |
Source code in src/data/datamodules/base_datamodule.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
__init__(cfg)
Initialize the ETDataModule instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Args
|
The configuration object. |
required |
Source code in src/data/datamodules/base_datamodule.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
create_dataloader(dataset, shuffle, sample_m_per_class=False, drop_last=False)
Create a DataLoader for the given dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
ETDataset
|
The dataset to create the DataLoader for. |
required |
shuffle
|
bool
|
Whether to shuffle the data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DataLoader |
DataLoader
|
The created DataLoader. |
Source code in src/data/datamodules/base_datamodule.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
create_etdataset(ia_scaler, fixation_scaler, trial_features_scaler, set_name, regime_name)
abstractmethod
Abstract method to create an ETDataset instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ia_scaler
|
MinMaxScaler | RobustScaler | StandardScaler
|
The IA scaler. |
required |
fixation_scaler
|
MinMaxScaler | RobustScaler | StandardScaler | None
|
Fixation scaler. |
required |
trial_features_scaler
|
MinMaxScaler | RobustScaler | StandardScaler | None
|
The trial features scaler. |
required |
regime_name
|
SetNames
|
The name of the regime (e.g., unseen_subject_seen_item). |
required |
set_name
|
SetNames
|
The name of the set (e.g., train, test, val). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ETDataset |
ETDataset
|
The created ETDataset instance. |
Source code in src/data/datamodules/base_datamodule.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
load_text_dataset()
Load the text dataset from a pickle file.
Returns:
| Name | Type | Description |
|---|---|---|
TextDataSet |
TextDataSet
|
The loaded text dataset. |
Source code in src/data/datamodules/base_datamodule.py
264 265 266 267 268 269 270 271 272 273 274 | |
predict_dataloader()
Create the DataLoader for the prediction datasets.
Returns:
| Type | Description |
|---|---|
list[DataLoader]
|
list[DataLoader]: A list of DataLoaders for the prediction datasets. |
Source code in src/data/datamodules/base_datamodule.py
226 227 228 229 230 231 232 233 | |
prepare_data()
Prepare the data for the module.
Source code in src/data/datamodules/base_datamodule.py
235 236 237 238 239 240 241 | |
setup(stage=None)
Set up the data module for training, validation, or testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stage
|
str | None
|
The stage of the setup. Can be "fit", "test", or "predict". |
None
|
Source code in src/data/datamodules/base_datamodule.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
test_dataloader()
Create the DataLoader for the test datasets.
Returns:
| Type | Description |
|---|---|
list[DataLoader]
|
list[DataLoader]: A list of DataLoaders for the test datasets. |
Source code in src/data/datamodules/base_datamodule.py
214 215 216 217 218 219 220 221 222 223 224 | |
text_dataset_create_if_needed()
If the text dataset does not exist or overwrite_data is True, create and save the text dataset.
Source code in src/data/datamodules/base_datamodule.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
train_dataloader()
Create the DataLoader for the training dataset.
Returns:
| Name | Type | Description |
|---|---|---|
DataLoader |
DataLoader
|
The DataLoader for the training dataset. |
Source code in src/data/datamodules/base_datamodule.py
188 189 190 191 192 193 194 195 196 197 198 199 200 | |
val_dataloader()
Create the DataLoader for the validation datasets.
Returns:
| Type | Description |
|---|---|
list[DataLoader]
|
list[DataLoader]: A list of DataLoaders for the validation datasets. |
Source code in src/data/datamodules/base_datamodule.py
202 203 204 205 206 207 208 209 210 211 212 | |
ETDataModuleFast
Bases: ETDataModule
A subclass of ETDataModule that includes checks to prevent redundant data preparation and setup. Based on the solution provided in https://github.com/Lightning-AI/pytorch-lightning/issues/16005
Attributes:
| Name | Type | Description |
|---|---|---|
prepare_data_done |
bool
|
A flag indicating whether the prepare_data method has been called. |
setup_stages_done |
set
|
A set storing the stages for which setup method has been called. |
Source code in src/data/datamodules/base_datamodule.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
__init__(*args, **kwargs)
Initialize the ETDataModuleFast instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
Variable length argument list to be passed to the ETDataModule constructor. |
()
|
**kwargs
|
object
|
Arbitrary keyword arguments to be passed to the ETDataModule constructor. |
{}
|
Source code in src/data/datamodules/base_datamodule.py
287 288 289 290 291 292 293 294 295 296 297 | |
prepare_data()
Prepare data for the module. If this method has been called before, it does nothing.
Source code in src/data/datamodules/base_datamodule.py
299 300 301 302 303 304 305 | |
setup(stage)
Set up the module for a specific stage. If this method has been called before for the same stage, it does nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stage
|
str
|
The stage for which to set up the module. |
required |
Source code in src/data/datamodules/base_datamodule.py
307 308 309 310 311 312 313 314 315 316 317 | |