maskers
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)
.
__init__
¶
__init__(percent_to_mask: float | Tensor, color_channels: int, patch_size: int | tuple[int, int] | Sequence[int]) -> None
Construct a BatchwiseChannelwisePatchwisePercentMasker
from the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
percent_to_mask |
float | Tensor
|
A scalar value between 0 and 1 inclusive, indicating the percentage of the largest input values to mask. |
required |
color_channels |
int
|
The number of color channels in the input tensor. |
required |
patch_size |
int | tuple[int, int] | Sequence[int]
|
The dimension of the non-overlapping rectangular patches the image is tiled with. |
required |
forward
¶
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
Tensor
|
The tensor over which to compute the thresholds. |
required |
selector_mask |
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 |
BatchwisePercentMasker
¶
Bases: PercentMasker
Constructs a mask based on a percentage of the highest values in the input tensor per batch element.
__init__
¶
Construct a layer to mask a percentage of input values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
percent_to_mask |
float | Tensor
|
A scalar value between 0 and 1 inclusive, indicating the percentage of the largest input values to mask. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
forward
¶
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
Tensor
|
The tensor over which to compute the threshold(s). |
required |
selector_mask |
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 |
Masker
¶
PercentMasker
¶
Bases: ThresholdMasker
Constructs a mask based on a percentage of the highest values in the input tensor.
__init__
¶
Construct a layer to mask a percentage of input values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
percent_to_mask |
float | Tensor
|
A scalar value between 0 and 1 inclusive, indicating the percentage of the largest input values to mask. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
forward
¶
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
Tensor
|
The tensor over which to compute the threshold(s). |
required |
selector_mask |
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 |
ThresholdMasker
¶
Bases: Masker
Defines an interface for constructing a mask from a threshold computed over an input tensor.
forward
¶
Construct a mask over the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
Tensor
|
The tensor over which to compute the threshold(s). |
required |
selector_mask |
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 |