campa.tl.Experiment

class Experiment(config)[source]

Experiment stored on disk with neural network.

Initialised with config dictionary with keys:

  • experiment: where to save experiment

    • dir: experiment folder

    • name: name of the experiment

    • save_config: (bool), whether to save this config in the folder

  • data: which dataset to use for training

    • data_config: name of the data config to use, should be registered in campa.ini

    • dataset_name: name of the dataset, relative to DATA_DIR

    • output_channels: Channels that should be predicted by the neural network. Defaults to all input channels.

  • model: model definition

    • model_cls: instance or value of ModelEnum

    • model_kwargs: keyword arguments passed to the model class

    • init_with_weights: if true, looks for saved weights in experiment_dir. if a path, loads these weights

  • training: training hyper-parameters

    • learning_rate: learning rate to use

    • epochs: number of epochs to train

    • batch_size: number of samples per batch

    • loss: mapping of model output names to values of LossEnum. Possible names are decoder and latent.

    • metrics: mapping of model output names to values of LossEnum.

    • save_model_weights: (bool) whether or not to save the model.

    • save_history: (bool) save csv with losses and metrics at each epoch.

    • overwrite_history: overwrite existing history csv file. Otherwise concatenate to it.

  • evaluation: evaluation on val/test split

    • split: train, val, or test

    • predict_reps: (list) model output that should be predicted. Possible values: decoder, latent.

    • img_ids: number of images to predict, or list of image ids.

    • predict_imgs: (bool) whether to predict reconstructed images.

    • predict_cluster_imgs: (bool) whether to predict clustered images.

  • cluster: clustering on val/test split

    • cluster_name: name of the clustering, used to save npy file.

    • cluster_rep: model output name to use for clustering, or “mpp”.

    • cluster_method: leiden or kmeans.

    • leiden_resolution: resolution parameter for leiden clustering.

    • subsample: None or “subsample”, whether or not to subsample data before clustering.

    • subsample_kwargs: passed to campa.data.MPPData.subsample() for creating the subsample data for clustering.

    • umap: (bool) predict UMAP of cluster_rep.

Parameters

config (MutableMapping[str, Any]) – Experiment config.

Attributes

config

Experiment config, see Experiment.

dir

Experiment directory.

epoch

Last epoch for which there is a trained model.

estimator_config

Config dictionary to initialise campa.tl.Estimator.

evaluate_config

Config dictionary to initialise campa.tl.Predictor.

full_path

Full path to Experiment.

is_trainable

Return false, if this is not a trainable experiment.

name

Experiment name.

Methods

from_dir(exp_path)

Initialise experiment from trained experiment in exp_path.

get_cluster_annotation([cluster_name, ...])

Read cluster_annotation file for full data from disk.

get_experiments_from_config(config_fname[, ...])

Initialise and return experiments from configs in config file.

get_experiments_from_dir(exp_dir[, ...])

Initialise and return experiments from experiment directory.

get_history()

Training history.

get_split_cluster_annotation([cluster_name])

Read cluster_annotation file for evaluation split from disk.

get_split_imgs_mpp_data()

Val_imgs / test_imgs MPPData read from results_epoch{self.epoch}`.

get_split_mpp_data()

Val or test MPPData read from results_epoch{self.epoch}.

set_to_evaluate()

Prepare Experiment for evaluation.