mmlearn.modules.layers.patch_dropout¶
Patch dropout layer.
Classes
Patch dropout layer. |
- class PatchDropout(keep_rate=0.5, bias=None, token_shuffling=False)[source]¶
Patch dropout layer.
Drops patch tokens (after embedding and adding CLS token) from the input tensor. Usually used in vision transformers to reduce the number of tokens. [1]
- Parameters:
References
- forward(x, force_drop=False)[source]¶
Drop tokens from the input tensor.
- Parameters:
x (torch.Tensor) – Input tensor of shape
(batch_sz, seq_len, dim)
.force_drop (bool, optional, default=False) – If True, the tokens are always dropped, even when the model is in evaluation mode.
- Returns:
Tensor of shape
(batch_sz, keep_len, dim)
containing the kept tokens.- Return type:
- uniform_mask(x)[source]¶
Generate token ids to keep from uniform random distribution.
- Parameters:
x (torch.Tensor) – Input tensor of shape
(batch_sz, seq_len, dim)
.- Returns:
Tensor of shape
(batch_sz, keep_len)
containing the token ids to keep.- Return type: