scvi.dataloaders.AnnDataLoader#
- class scvi.dataloaders.AnnDataLoader(adata_manager, indices=None, batch_size=128, shuffle=False, sampler=None, drop_last=False, drop_dataset_tail=False, data_and_attributes=None, iter_ndarray=False, distributed_sampler=False, load_sparse_tensor=False, **kwargs)[source]#
Bases:
DataLoaderDataLoader for loading tensors from AnnData objects.
- Parameters:
- adata_manager
AnnDataManager AnnDataManagerobject with a registered AnnData object.- indices
list[int] |list[bool] |None(default:None) The indices of the observations in
adata_manager.adatato load.- batch_size
int(default:128) Minibatch size to load each iteration. If
distributed_samplerisTrue, refers to the minibatch size per replica. Thus, the effective minibatch size isbatch_size*num_replicas.- shuffle
bool(default:False) Whether the dataset should be shuffled prior to sampling.
- sampler
Sampler|None(default:None) Defines the strategy to draw samples from the dataset. Can be any Iterable with __len__ implemented. If specified, shuffle must not be specified. By default, we use a custom sampler that is designed to get a minibatch of data with one call to __getitem__.
- drop_last
bool(default:False) If
Trueand the dataset is not evenly divisible bybatch_size, the last incomplete batch is dropped. IfFalseand the dataset is not evenly divisible bybatch_size, then the last batch will be smaller thanbatch_size.- drop_dataset_tail
bool(default:False) Only used if
distributed_samplerisTrue. IfTruethe sampler will drop the tail of the dataset to make it evenly divisible by the number of replicas. IfFalse, then the sampler will add extra indices to make the dataset evenly divisible by the number of replicas.- data_and_attributes
list[str] |dict[str,dtype] |None(default:None) Dictionary with keys representing keys in data registry (
adata_manager.data_registry) and value equal to desired numpy loading type (later made into torch tensor) or list of such keys. A list can be used to subset to certain keys in the event that more tensors than needed have been registered. IfNone, defaults to all registered data.- iter_ndarray
bool(default:False) Whether to iterate over numpy arrays instead of torch tensors
- distributed_sampler
bool(default:False) EXPERIMENTALWhether to useBatchDistributedSampleras the sampler. IfTrue,samplermust beNone.- load_sparse_tensor
bool(default:False) EXPERIMENTALIfTrue, loads data with sparse CSR or CSC layout as aTensorwith the same layout. Can lead to speedups in data transfers to GPUs, depending on the sparsity of the data.- **kwargs
Additional keyword arguments passed into
DataLoader.
- adata_manager
Notes
If
sampleris not specified, aBatchSamplerinstance is passed in as the sampler, which retrieves a minibatch of data with one call to__getitem__onAnnTorchDataset. This is useful for fast access to sparse matrices as retrieving single observations and then collating is inefficient.
Attributes table#
Methods table#
Attributes#
- AnnDataLoader.dataset#
- AnnDataLoader.batch_size#
- AnnDataLoader.num_workers#
- AnnDataLoader.pin_memory#
- AnnDataLoader.drop_last#
- AnnDataLoader.timeout#
- AnnDataLoader.sampler#
- AnnDataLoader.pin_memory_device#
- AnnDataLoader.prefetch_factor#