load_posterior¶
-
scvi.inference.
load_posterior
(dir_path, model, use_cuda='auto', **posterior_kwargs)[source]¶ Function to use in order to retrieve a posterior that was saved using the
save_posterior
methodBecause of pytorch model loading usage, this function needs a scVI model object initialized with exact same parameters that during training. Because saved posteriors correspond to already trained models, data is loaded sequentially using a
SequentialSampler
.- Parameters
dir_path (
str
str
) – directory containing the posterior properties to be retrieved.model (
Module
Module
) – scVI initialized model.use_cuda (
str
,bool
,None
Union
[str
,bool
,None
]) – Specifies if the computations should be perfomed with a GPU. Default:True
Ifauto
, then cuda availability is inferred, with a preference to load on GPU. IfFalse
, the model will be loaded on the CPU, even if it was trained using a GPU.**posterior_kwargs – additional parameters to feed to the posterior constructor.
- Returns
>>> model = VAE(nb_genes, n_batches, n_hidden=128, n_latent=10) >>> trainer = UnsupervisedTrainer(vae, dataset, train_size=0.5, use_cuda=use_cuda) >>> trainer.train(n_epochs=200) >>> trainer.train_set.save_posterior("./my_run_train_posterior")
>>> model = VAE(nb_genes, n_batches, n_hidden=128, n_latent=10) >>> post = load_posterior("./my_run_train_posterior", model=model)