scvi.nn.FCLayers#
- class scvi.nn.FCLayers(n_in, n_out, n_cat_list=None, n_layers=1, n_hidden=128, dropout_rate=0.1, use_batch_norm=True, use_layer_norm=False, use_activation=True, bias=True, inject_covariates=True, activation_fn=<class 'torch.nn.modules.activation.ReLU'>)[source]#
Bases:
Module
A helper class to build fully-connected layers for a neural network.
- Parameters:
- n_in :
int
The dimensionality of the input
- n_out :
int
The dimensionality of the output
- n_cat_list :
Iterable
[int
] |None
Optional
[Iterable
[int
]] (default:None
) A list containing, for each category of interest, the number of categories. Each category will be included using a one-hot encoding.
- n_layers :
int
(default:1
) The number of fully-connected hidden layers
- n_hidden :
int
(default:128
) The number of nodes per hidden layer
- dropout_rate :
float
(default:0.1
) Dropout rate to apply to each of the hidden layers
- use_batch_norm :
bool
(default:True
) Whether to have BatchNorm layers or not
- use_layer_norm :
bool
(default:False
) Whether to have LayerNorm layers or not
- use_activation :
bool
(default:True
) Whether to have layer activation or not
- bias :
bool
(default:True
) Whether to learn bias in linear layers or not
- inject_covariates :
bool
(default:True
) Whether to inject covariates in each layer, or just the first (default).
- activation_fn :
Module
(default:<class 'torch.nn.modules.activation.ReLU'>
) Which activation function to use
- n_in :
Attributes table#
Methods table#
|
Forward computation on |
|
Helper to determine if covariates should be injected. |
|
Attributes#
T_destination#
alias of TypeVar(‘T_destination’, bound=Mapping
[str
, Tensor
])
.. autoattribute:: FCLayers.T_destination
dump_patches
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- FCLayers.dump_patches: bool = False#
This allows better BC support for
load_state_dict()
. Instate_dict()
, the version number will be saved as in the attribute _metadata of the returned state dict, and thus pickled. _metadata is a dictionary with keys that follow the naming convention of state dict. See_load_from_state_dict
on how to use this information in loading.If new parameters/buffers are added/removed from a module, this number shall be bumped, and the module’s _load_from_state_dict method can compare the version number and do appropriate changes if the state dict is from before the change.
training#
Methods#
forward#
- FCLayers.forward(x, *cat_list)[source]#
Forward computation on
x
.- Parameters:
- x : torch.Tensor
tensor of values with shape
(n_in,)
- cat_list :
int
list of category membership(s) for this sample
- x
- Returns:
py:class:torch.Tensor tensor of shape
(n_out,)