Trainers Module
GeneralTrainer
Bases: BaseTrainer
Handles general training logic for autoencoder models.
Attributes:
| Name | Type | Description |
|---|---|---|
_trainset |
The dataset used for training. |
|
_validset |
The dataset used for validation, if provided. |
|
_result |
An object to store and manage training results. |
|
_config |
Configuration object containing training hyperparameters and settings. |
|
_model_type |
The autoencoder model class to be trained. |
|
_loss_fn |
Instantiated loss function specific to the model. |
|
_trainloader |
DataLoader for the training dataset. |
|
_validloader |
DataLoader for the validation dataset, if provided. |
|
_model |
The instantiated model architecture. |
|
_optimizer |
The optimizer used for training. |
|
_fabric |
Lightning Fabric wrapper for device and precision management. |
|
n_train |
Number of training samples. |
|
n_valid |
Number of validation samples. |
|
n_test |
Optional[int]
|
Number of test samples (set during prediction). |
n_features |
Number of input features. |
|
latent_dim |
Dimensionality of the latent space. |
|
device |
Device on which the model is located. |
|
_n_cpus |
Number of CPU cores available. |
|
_reconstruction_buffer |
Buffer to store reconstructions during training/validation/testing. |
|
_latentspace_buffer |
Buffer to store latent representations during training/validation/testing. |
|
_mu_buffer |
Buffer to store latent means (for VAE) during training/validation |
|
_sigma_buffer |
Buffer to store latent log-variances (for VAE) during training/validation/testing. |
|
_sample_ids_buffer |
Buffer to store sample IDs during training/validation/testing. |
Source code in src/autoencodix/trainers/_general_trainer.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 275 276 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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
__init__(trainset, validset, result, config, model_type, loss_type, ontologies=None, **kwargs)
Initializes the GeneralTrainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainset
|
Optional[BaseDataset]
|
The dataset used for training. |
required |
validset
|
Optional[BaseDataset]
|
The dataset used for validation, if provided. |
required |
result
|
Result
|
An object to store and manage training results. |
required |
config
|
DefaultConfig
|
Configuration object containing training hyperparameters and settings. |
required |
model_type
|
Type[BaseAutoencoder]
|
The autoencoder model class to be trained. |
required |
loss_type
|
Type[BaseLoss]
|
The loss function class to be used for training. |
required |
ontologies
|
Optional[Union[Tuple, List]]
|
Ontology information, if provided for Ontix |
None
|
Source code in src/autoencodix/trainers/_general_trainer.py
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 | |
decode(x)
Decodes the input tensor x using the trained model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor to be decoded. |
required |
Returns: Decoded tensor.
Source code in src/autoencodix/trainers/_general_trainer.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
get_model()
Getter method for the trained model.
Returns:
The trained model as a torch.nn.Module.
Source code in src/autoencodix/trainers/_general_trainer.py
454 455 456 457 458 459 460 461 | |
maskix_hook(X)
Only active when override from MaskixTrainer is used
Source code in src/autoencodix/trainers/_general_trainer.py
170 171 172 | |
predict(data, model=None, **kwargs)
Decided to add predict method to the trainer class.
This violates SRP, but the trainer class has a lot of attributes and methods that are needed for prediction. So this way we don't need to write so much duplicate code
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
BaseDataset
|
BaseDataset unseen data to run inference on |
required |
model
|
Optional[Module]
|
torch.nn.Module model to run inference with |
None
|
**kwargs
|
Additional arguments (not used here). |
{}
|
Returns:
| Type | Description |
|---|---|
Result
|
self._result: Result object containing the inference results |
Source code in src/autoencodix/trainers/_general_trainer.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
purge()
Cleans up any resources used during training, such as cached data or large attributes.
Source code in src/autoencodix/trainers/_general_trainer.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
train(epochs_overwrite=None)
Orchestrates training over multiple epochs, including training and validation phases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epochs_overwrite
|
If provided, overrides the number of epochs specified in the config. This is only there so we can use the train method for pretraining.Any |
None
|
Returns: Result object containing training results and dynamics like latent spaces and reconstructions.
Source code in src/autoencodix/trainers/_general_trainer.py
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 | |
StackixOrchestrator
StackixOrchestrator coordinates the training of multi-modality VAE stacking.
This orchestrator manages both parallel and sequential training of modality-specific autoencoders, followed by creating a concatenated latent space for the final stacked model training. It leverages Lightning Fabric's distribution strategies for efficient training.
Attributes: _workdir: Directory for saving intermediate models and results modality_models: Dictionary of trained models for each modality modality_results: Dictionary of training results for each modality _modality_latent_dims: Dictionary of latent dimensions for each modality concatenated_latent_spaces: Dictionary of concatenated latent spaces by split _dataset_type: Class to use for creating datasets _fabric: Lightning Fabric instance for distributed operations _trainer_class: Class to use for training (dependency injection) trainset: Training dataset containing multiple modalities validset: Validation dataset containing multiple modalities testset: Test dataset containing multiple modalities loss_type: Type of loss function to use for training model_type: Type of autoencoder model to use for each modality config: Configuration parameters for training and model architecture stacked_model: The final stacked autoencoder model (initialized later) stacked_trainer: Trainer for the stacked model (initialized later) concat_idx: Dictionary tracking the start and end indices of each modality in the concatenated latent space dropped_indices_map: Dictionary tracking dropped sample indices for each modality during alignment reconstruction_shapes: Dictionary storing original shapes of latent spaces for reconstruction common_sample_ids: Common sample IDs across all modalities for alignment
Source code in src/autoencodix/trainers/_stackix_orchestrator.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 275 276 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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
__init__(trainset, validset, config, model_type, loss_type, testset=None, trainer_type=GeneralTrainer, dataset_type=NumericDataset, workdir='./stackix_work')
Initialize the StackixOrchestrator with datasets and configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainset
|
Optional[MultiModalDataset]
|
Training dataset containing multiple modalities |
required |
validset
|
Optional[MultiModalDataset]
|
Validation dataset containing multiple modalities |
required |
config
|
DefaultConfig
|
Configuration parameters for training and model architecture |
required |
model_type
|
Type[BaseAutoencoder]
|
Type of autoencoder model to use for each modality |
required |
loss_type
|
Type[BaseLoss]
|
Type of loss function to use for training |
required |
testset
|
Optional[MultiModalDataset]
|
Dataset with test split |
None
|
trainer_type
|
Type[GeneralTrainer]
|
Type to use for training (default is GeneralTrainer) |
GeneralTrainer
|
dataset_type
|
Type[BaseDataset]
|
Type to use for creating datasets (default is NumericDataset) |
NumericDataset
|
workdir
|
str
|
Directory to save intermediate models and results (default is "./stackix_work") |
'./stackix_work'
|
Source code in src/autoencodix/trainers/_stackix_orchestrator.py
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 | |
predict_modalities(data)
Predicts using the trained models for each modality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
MultiModalDataset
|
Input data for prediction, uses test data if not provided |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Tensor]
|
Dictionary of reconstructed tensors by modality |
Raises:
| Type | Description |
|---|---|
ValueError
|
If model has not been trained yet or no data is available |
Source code in src/autoencodix/trainers/_stackix_orchestrator.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
prepare_latent_datasets(split)
Prepares datasets with concatenated latent spaces for stacked model training.
This is the second phase of Stackix training where latent spaces from all modalities are extracted and concatenated.
Returns:
| Type | Description |
|---|---|
NumericDataset
|
Training and validation datasets with concatenated latent spaces |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no modality models have been trained or no latent spaces could be extracted |
Source code in src/autoencodix/trainers/_stackix_orchestrator.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
reconstruct_from_stack(reconstructed_stack)
Reconstructs the full data for each modality from the stacked latent reconstruction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reconstructed_stack
|
Tensor
|
Tensor with the reconstructed concatenated latent space |
required |
Returns: Dictionary of reconstructed tensors by modality
Source code in src/autoencodix/trainers/_stackix_orchestrator.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
set_testset(testset)
Set the test dataset for the orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
testset
|
MultiModalDataset
|
Test dataset containing multiple modalities |
required |
Source code in src/autoencodix/trainers/_stackix_orchestrator.py
121 122 123 124 125 126 127 | |
train_modalities()
Trains all modality-specific models.
This is the first phase of Stackix training where each modality is trained independently before their latent spaces are combined.
Returns:
| Type | Description |
|---|---|
Dict[str, BaseAutoencoder]
|
Dictionary of trained models for each modality and Dictionary of training results |
Dict[str, Result]
|
for each modality. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If trainset is not a MultiModalDataset or has no modalities |
Source code in src/autoencodix/trainers/_stackix_orchestrator.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
StackixTrainer
Bases: GeneralTrainer
StackixTrainer is a wrapper for StackixOrchestrator that conforms to the BaseTrainer interface.
This trainer maintains compatibility with the BasePipeline interface while leveraging the more modular and well-designed StackixOrchestrator classes for the actual implementation.
Attributes: _workdir: Directory for saving intermediate models and results _result: Result object to store training outcomes _config: Configuration parameters for training and model architecture _model_type: Type of autoencoder model to use for each modality _loss_type: Type of loss function to use for training _trainset: Training dataset containing multiple modalities _validset: Validation dataset containing multiple modalities _orchestrator_type: Type to use for orchestrating modality training (default is StackixOrchestrator) _trainer_type: Type to use for training each modality model (default is GeneralTrainer) _modality_trainers: Dictionary of trained models for each modality _modality_results: Dictionary of training results for each modality _trainer: Trainer for the stacked model _fabric: Lightning Fabric wrapper for device and precision management _train_latent_ds: Training dataset with concatenated latent spaces _valid_latent_ds: Validation dataset with concatenated latent spaces concat_idx: Indices used for concatenating latent spaces _model: The instantiated stacked model architecture _optimizer: The optimizer used for training _orchestrator: The orchestrator that manages modality model training and latent space preparation _workdir: Directory for saving intermediate models and results
Source code in src/autoencodix/trainers/_stackix_trainer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 | |
__init__(trainset, validset, result, config, model_type, loss_type, orchestrator_type=StackixOrchestrator, trainer_type=GeneralTrainer, workdir='./stackix_work', ontologies=None, **kwargs)
Initialize the StackixTrainer with datasets and configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainset
|
Optional[StackixDataset]
|
Training dataset containing multiple modalities |
required |
validset
|
Optional[StackixDataset]
|
Validation dataset containing multiple modalities |
required |
result
|
Result
|
Result object to store training outcomes |
required |
config
|
DefaultConfig
|
Configuration parameters for training and model architecture |
required |
model_type
|
Type[BaseAutoencoder]
|
Type of autoencoder model to use for each modality |
required |
loss_type
|
Type[BaseLoss]
|
Type of loss function to use for training |
required |
orchestrator_type
|
Type[StackixOrchestrator]
|
Type to use for orchestrating modality training (default is StackixOrchestrator) |
StackixOrchestrator
|
trainer_type
|
Type[BaseTrainer]
|
Type to use for training each modality model (default is GeneralTrainer) |
GeneralTrainer
|
workdir
|
str
|
Directory to save intermediate models and results (default is "./stackix_work") |
'./stackix_work'
|
onotologies
|
Ontology information, if provided for Ontix compatibility |
required |
Source code in src/autoencodix/trainers/_stackix_trainer.py
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 | |
get_model()
Getter for the the trained model.
Returns:
| Type | Description |
|---|---|
Module
|
The trained model |
Source code in src/autoencodix/trainers/_stackix_trainer.py
112 113 114 115 116 117 118 | |
predict(data, model=None, **kwargs)
Make predictions on the given dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
BaseDataset
|
The dataset to make predictions on. |
required |
model
|
Optional[Module]
|
The model to use for predictions. If None, uses the trained model. |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns: Result: The prediction results including reconstructions and latent spaces.
Source code in src/autoencodix/trainers/_stackix_trainer.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
train()
Train the stacked model on the concatenated latent space.
Uses the standard BaseTrainer training process but with the stacked model.
Returns:
| Type | Description |
|---|---|
Result
|
Training results including losses, latent spaces, and other metrics |
Source code in src/autoencodix/trainers/_stackix_trainer.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
XModalTrainer
Bases: BaseTrainer
Trainer for cross-modal autoencoders, implements multimodal training with adversarial component.
Attributes:
| Name | Type | Description |
|---|---|---|
_trainset |
The dataset used for training, must be a MultiModalDataset. |
|
_n_train_modalities |
Number of modalities in the training dataset. |
|
model_map |
Mapping from DataSetTypes to specific autoencoder architectures. |
|
model_trainer_map |
Mapping from autoencoder architectures to their corresponding trainer classes. |
|
_n_cpus |
Number of CPU cores available for data loading. |
|
latent_dim |
Dimensionality of the shared latent space. |
|
n_test |
Optional[int]
|
Number of samples in the test set, if provided. |
n_train |
Number of samples in the training set. |
|
n_valid |
Number of samples in the validation set, if provided. |
|
n_features |
Total number of features across all modalities. |
|
_cur_epoch |
int
|
Current epoch number during training. |
_is_checkpoint_epoch |
Optional[bool]
|
Flag indicating if the current epoch is a checkpoint epoch. |
_sub_loss_type |
Loss function type for individual modality autoencoders. |
|
sub_loss |
Instantiated loss function for individual modality autoencoders. |
|
_clf_epoch_loss |
float
|
Cumulative classifier loss for the current epoch. |
_epoch_loss |
float
|
Cumulative total loss for the current epoch. |
_epoch_loss_valid |
float
|
Cumulative total validation loss for the current epoch. |
_modality_dynamics |
float
|
Dictionary holding model, optimizer, and training state for each modality. |
_latent_clf |
float
|
Classifier model for adversarial training on latent spaces. |
_clf_optim |
float
|
Optimizer for the classifier model. |
_clf_loss_fn |
float
|
Loss function for the classifier. |
_trainloader |
float
|
DataLoader for the training dataset. |
_validloader |
float
|
DataLoader for the validation dataset, if provided. |
_model |
float
|
The instantiated stacked model architecture. |
_validset |
The dataset used for validation, if provided, must be a MultiModalDataset. |
|
_fabric |
Lightning Fabric wrapper for device and precision management. |
Source code in src/autoencodix/trainers/_xmodal_trainer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 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 275 276 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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
__init__(trainset, validset, result, config, model_type, loss_type, sub_loss_type=VarixLoss, model_map={DataSetTypes.NUM: VarixArchitecture, DataSetTypes.IMG: ImageVAEArchitecture}, ontologies=None, **kwargs)
Initializes the XModalTrainer with datasets and configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainset
|
MultiModalDataset
|
Training dataset containing multiple modalities |
required |
validset
|
MultiModalDataset
|
Validation dataset containing multiple modalities |
required |
result
|
Result
|
Result object to store training outcomes |
required |
config
|
DefaultConfig
|
Configuration parameters for training and model architecture |
required |
model_type
|
Type[BaseAutoencoder]
|
Type of autoencoder model to use for each modality (not used directly) |
required |
loss_type
|
Type[BaseLoss]
|
Type of loss function to use for training the stacked model |
required |
sub_loss_type
|
Type[BaseLoss]
|
Type of loss function to use for individual modality autoencoders |
VarixLoss
|
model_map
|
Dict[DataSetTypes, Type[BaseAutoencoder]]
|
Mapping from DataSetTypes to specific autoencoder architectures |
{NUM: VarixArchitecture, IMG: ImageVAEArchitecture}
|
ontologies
|
Optional[Union[Tuple, List]]
|
Ontology information, for compatibility with Ontix |
None
|
Source code in src/autoencodix/trainers/_xmodal_trainer.py
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 | |
decode(x)
Decodes input latent representations Args: x: Latent representations to decode, shape (n_samples, latent_dim)
Source code in src/autoencodix/trainers/_xmodal_trainer.py
538 539 540 541 542 543 | |
predict(data, model=None, **kwargs)
Performs cross-modal prediction from a specified 'from' modality to a 'to' modality.
The direction is determined by the 'translate_direction' attribute in the config. Results are stored in the Result object under split='test' and epoch=-1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
BaseDataset
|
A MultiModalDataset containing the input data for the 'from' modality. |
required |
Returns:
| Type | Description |
|---|---|
Result
|
The Result object populated with prediction results. |
Source code in src/autoencodix/trainers/_xmodal_trainer.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
purge()
Cleans up all instantiated resources used during training, including all modality-specific models/optimizers and the adversarial classifier.
Source code in src/autoencodix/trainers/_xmodal_trainer.py
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
train()
Orchestrates the full training process for the cross-modal autoencoder.
Source code in src/autoencodix/trainers/_xmodal_trainer.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |