fusilli.fusionmodels.tabularimagefusion.denoise_tab_img_mapsο
Denoising autoencoder for tabular data concatenated with image feature maps
Classes
|
Using a denoising autoencoder to upsample tabular data, then concatenating with feature maps from final 3 conv layers of image data. |
|
Denoising autoencoder for tabular data: pytorch lightning module. |
|
Image unimodal network to go alongside the tabular denoising autoencoder: pytorch lightning module. |
|
Class containing the method to train the denoising autoencoder and to convert the image data to the latent image space. |
- class DAETabImgMaps(prediction_task, data_dims, multiclass_dimensions)[source]ο
Bases:
ParentFusionModel,ModuleUsing a denoising autoencoder to upsample tabular data, then concatenating with feature maps from final 3 conv layers of image data. From Yan et al 2021: Richer fusion network for breast cancer classification on multimodal data.
- prediction_taskο
Type of prediction.
- Type:
str
- subspace_methodο
Subspace method:
denoising_autoencoder_subspace_method.- Type:
class
- fusion_layersο
Fusion layers combining the intermediate image maps and the tabular latent subspace.
- Type:
nn.Sequential
- final_predictionο
Final prediction layers.
- Type:
nn.Sequential
- __init__(prediction_task, data_dims, multiclass_dimensions)[source]ο
- Parameters:
prediction_task (str) β Type of prediction to be performed.
data_dims (list) β List containing the dimensions of the data.
multiclass_dimensions (int) β Number of classes in the multiclass classification task.
- forward(x)[source]ο
Forward pass.
- Parameters:
x (torch.Tensor) β Input data.
- Returns:
out β Output tensor.
- Return type:
torch.Tensor
- fusion_type = 'subspace'ο
Type of fusion.
- Type:
str
- method_name = 'Denoising tabular autoencoder with image maps'ο
Name of the method.
- Type:
str
- modality_type = 'tabular_image'ο
Type of modality.
- Type:
str
- subspace_methodο
- class DenoisingAutoencoder(data_dims)[source]ο
Bases:
LightningModuleDenoising autoencoder for tabular data: pytorch lightning module.
- tab_dimsο
Dimension of the input tabular data.
- Type:
int
- upsamplerο
Upsampling layers.
- Type:
nn.Sequential
- downsamplerο
Downsampling layers.
- Type:
nn.Sequential
- lossο
Loss function. In this case, itβs the mean squared error.
- Type:
nn function
- __init__(data_dims)[source]ο
Initialise the model.
- Parameters:
data_dims (list) β List containing the dimensions of the data.
- configure_optimizers()[source]ο
Configure the optimizers of the model.
- Returns:
Adam optimizer.
- Return type:
torch.optim.Adam
- denoise(x)[source]ο
Denoise the data to create the latent subspace.
- Parameters:
x (torch.Tensor) β Input data.
- Returns:
Latent subspace.
- Return type:
torch.Tensor
- forward(x)[source]ο
Forward pass.
- Parameters:
x (torch.Tensor) β Input data.
- Returns:
List containing the output.
- Return type:
list
- class ImgUnimodalDAE(data_dims, prediction_task, multiclass_dimensions)[source]ο
Bases:
LightningModuleImage unimodal network to go alongside the tabular denoising autoencoder: pytorch lightning module.
- img_dimο
Dimension of the input image data.
- Type:
int
- multiclass_dimensionsο
Number of classes for multiclass classification.
- Type:
int
- img_layersο
Image layers.
- Type:
nn.ModuleDict
- num_layersο
Number of image layers.
- Type:
int
- fused_dimο
Dimension of the fused layers. Final dimension of the image data after image layers.
- Type:
int
- prediction_taskο
Type of prediction.
- Type:
str
- lossο
Loss function. Depends on the prediction type.
- Type:
function
- fused_layersο
Fused layers.
- Type:
nn.Sequential
- final_predictionο
Final prediction layers.
- Type:
nn.Sequential
- lossο
Loss function. Depends on the prediction type.
- Type:
function
- activationο
Activation function. Depends on the prediction type.
- Type:
function
- __init__(data_dims, prediction_task, multiclass_dimensions)[source]ο
Initialise the model.
- Parameters:
data_dims (list) β List containing the dimensions of the data.
prediction_task (str) β Type of prediction.
multiclass_dimensions (int) β Number of classes for multiclass classification.
- configure_optimizers()[source]ο
Configure the optimizers of the model.
- Returns:
Adam optimizer.
- Return type:
torch.optim.Adam
- forward(x)[source]ο
Forward pass.
- Parameters:
x (torch.Tensor) β Input data.
- Returns:
List containing the output.
- Return type:
list
- get_intermediate_featuremaps(x)[source]ο
Get the intermediate feature maps to concatenate with the tabular latent subspace.
- Parameters:
x (torch.Tensor) β Input data.
- Returns:
Intermediate feature maps.
- Return type:
torch.Tensor
- class denoising_autoencoder_subspace_method(datamodule, k=None, max_epochs=1000, train_subspace=True)[source]ο
Bases:
objectClass containing the method to train the denoising autoencoder and to convert the image data to the latent image space.
- datamoduleο
Data module containing the data.
- Type:
pl.LightningDataModule
- dae_trainerο
Trainer for the denoising autoencoder.
- Type:
pl.Trainer
- img_unimodal_trainerο
Trainer for the image unimodal network.
- Type:
pl.Trainer
- autoencoderο
Tabular denoising autoencoder.
- Type:
- img_unimodalο
Image unimodal network.
- Type:
- __init__(datamodule, k=None, max_epochs=1000, train_subspace=True)[source]ο
- Parameters:
datamodule (pl.LightningDataModule) β Data module containing the data.
k (int or None) β Number of subspaces. Default is None.
max_epochs (int) β Maximum number of epochs. Default is 1000.
train_subspace (bool) β Whether to train the subspace models. Default is True.
- convert_to_latent(test_dataset)[source]ο
Convert the image data to the latent image space.
- Parameters:
test_dataset (Dataset) β Test dataset.
- Returns:
list β List containing the raw tabular data and the latent image space.
pd.DataFrame β Dataframe containing the labels.
list β List containing the dimensions of the data.
- load_ckpt(checkpoint_path)[source]ο
Load the checkpoint of the subspace models
- Parameters:
checkpoint_path (list) β Paths to the checkpoints. The checkpoint list must be a list of checkpoint elements containing the state dict of the subspace models.
- train(train_dataset, val_dataset)[source]ο
Train the latent image space.
- Parameters:
train_dataset (Dataset) β Training dataset.
val_dataset (Dataset) β Validation dataset.
- Returns:
list β List containing the raw tabular data and the latent image space.
pd.DataFrame β Dataframe containing the labels.