maskers
Modules:
Name | Description |
---|---|
conv |
Utility functions for convolutional operations. |
version |
Constants storing the version numbers for major changes to the codebase. |
Classes:
Name | Description |
---|---|
BatchwiseChannelwisePatchwisePercentMasker |
Constructs a mask based on a percentage of the highest values in the input tensor per batch element, per color channel, per patch. |
BatchwisePercentMasker |
Constructs a mask based on a percentage of the highest values in the input tensor per batch element. |
Masker |
Defines an interface for masking input values. |
PercentMasker |
Constructs a mask based on a percentage of the highest values in the input tensor. |
ThresholdMasker |
Defines an interface for constructing a mask from a threshold computed over an input tensor. |
BatchwiseChannelwisePatchwisePercentMasker
¶
Bases: PercentMasker
Constructs a mask based on a percentage of the highest values in the input tensor per batch element, per color channel, per patch.
This class is designed to be used with 2D convolutional layers that output tensors of shape
(batch_size, color_channels * patch_area, patches_high, patches_wide)
.
Methods:
Name | Description |
---|---|
__init__ |
Construct a |
forward |
Construct a mask over the input tensor. |
reset_parameters |
Reinitialize parameters and buffers. |
__init__
¶
__init__(percent_to_mask: float, color_channels: int, patch_size: int | tuple[int, int] | Sequence[int]) -> None
Construct a BatchwiseChannelwisePatchwisePercentMasker
from the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
float
|
A scalar value between 0 and 1 inclusive, indicating the percentage of the largest input values to mask. |
required |
|
int
|
The number of color channels in the input tensor. |
required |
|
int | tuple[int, int] | Sequence[int]
|
The dimension of the non-overlapping rectangular patches the image is tiled with. |
required |
forward
¶
forward(input: Tensor, selector_mask: Tensor | None = None) -> torch.Tensor
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Tensor
|
The tensor over which to compute the thresholds. |
required |
|
Tensor | None
|
Unsupported. In the parent class, a mask tensor to use to select a subset of the elements of |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
A mask tensor of the same shape as |
Raises:
Type | Description |
---|---|
ValueError
|
If |
reset_parameters
¶
Reinitialize parameters and buffers.
This method is useful for initializing tensors created on the meta device.
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
BatchwisePercentMasker
¶
Bases: PercentMasker
Constructs a mask based on a percentage of the highest values in the input tensor per batch element.
Methods:
Name | Description |
---|---|
__init__ |
Construct a layer to mask a percentage of input values. |
forward |
Construct a mask over the input tensor. |
reset_parameters |
Reinitialize parameters and buffers. |
__init__
¶
__init__(percent_to_mask: float) -> None
forward
¶
forward(input: Tensor, selector_mask: Tensor | None = None) -> torch.Tensor
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Tensor
|
The tensor over which to compute the threshold(s). |
required |
|
Tensor | None
|
A mask tensor to use to select a subset of the elements of |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
A mask tensor of the same shape as |
reset_parameters
¶
Reinitialize parameters and buffers.
This method is useful for initializing tensors created on the meta device.
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
Masker
¶
Defines an interface for masking input values.
Masker
s should return a boolean tensor of the same shape as the input tensor.
Added in version 0.30.0.
Methods:
Name | Description |
---|---|
reset_parameters |
Reinitialize parameters and buffers. |
reset_parameters
abstractmethod
¶
Reinitialize parameters and buffers.
This method is useful for initializing tensors created on the meta device.
PercentMasker
¶
Bases: ThresholdMasker
Constructs a mask based on a percentage of the highest values in the input tensor.
Methods:
Name | Description |
---|---|
__init__ |
Construct a layer to mask a percentage of input values. |
forward |
Construct a mask over the input tensor. |
reset_parameters |
Reinitialize parameters and buffers. |
__init__
¶
__init__(percent_to_mask: float) -> None
forward
¶
forward(input: Tensor, selector_mask: Tensor | None = None) -> torch.Tensor
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Tensor
|
The tensor over which to compute the threshold(s). |
required |
|
Tensor | None
|
A mask tensor to use to select a subset of the elements of |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
A mask tensor of the same shape as |
reset_parameters
¶
Reinitialize parameters and buffers.
This method is useful for initializing tensors created on the meta device.
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
ThresholdMasker
¶
Bases: Masker
Defines an interface for constructing a mask from a threshold computed over an input tensor.
Methods:
Name | Description |
---|---|
forward |
Construct a mask over the input tensor. |
reset_parameters |
Reinitialize parameters and buffers. |
forward
¶
forward(input: Tensor, selector_mask: Tensor | None = None) -> torch.Tensor
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Tensor
|
The tensor over which to compute the threshold(s). |
required |
|
Tensor | None
|
A mask tensor to use to select a subset of the elements of |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
A mask tensor of the same shape as |
reset_parameters
abstractmethod
¶
Reinitialize parameters and buffers.
This method is useful for initializing tensors created on the meta device.