AE¶
- class behavenet.models.aes.AE(hparams)[source]¶
Bases:
BaseModelBase autoencoder class.
This class can construct both linear and convolutional autoencoders. The linear autoencoder utilizes a single hidden layer, dense feedforward layers (i.e. not convolutional), and the encoding and decoding weights are tied to more closely resemble PCA/SVD. The convolutional autoencoder architecture is defined by various keys in the dict that serves as the constructor input. See the
behavenet.models.ae_model_architecture_generatormodule to see examples for how this is done.Methods Summary
Construct the model using hparams.
forward(x[, dataset])Process input data.
loss(data[, dataset, accumulate_grad, ...])Calculate MSE loss for autoencoder.
Methods Documentation
- forward(x, dataset=None, **kwargs)[source]¶
Process input data.
- Parameters:
x (
torch.Tensorobject) – input datadataset (
int) – used with session-specific io layers
- Returns:
y (
torch.Tensor): output of shape (n_frames, n_channels, y_pix, x_pix)x (
torch.Tensor): hidden representation of shape (n_frames, n_latents)
- Return type:
tuple
- loss(data, dataset=0, accumulate_grad=True, chunk_size=200)[source]¶
Calculate MSE loss for autoencoder.
The batch is split into chunks if larger than a hard-coded chunk_size to keep memory requirements low; gradients are accumulated across all chunks before a gradient step is taken.
- Parameters:
data (
dict) – batch of data; keys should include ‘images’ and ‘masks’, if necessarydataset (
int, optional) – used for session-specific io layersaccumulate_grad (
bool, optional) – accumulate gradient for training stepchunk_size (
int, optional) – batch is split into chunks of this size to keep memory requirements low
- Returns:
‘loss’ (
float): mse loss
- Return type:
dict