EncoderMixin¶
- class EncoderMixin[source]¶
Mixin class adding encoder-specific functionality.
Provides methods for: - Managing output channels for encoder feature maps. - Patching the first convolution for arbitrary input channels. - Converting encoder to dilated version for segmentation tasks.
Example
>>> encoder = EncoderMixin() >>> encoder.set_in_channels(1)
Initialize EncoderMixin with default parameters.
Sets default values for encoder depth, input channels, output stride, and output channel list.
Methods
Return encoder stages for dilation modification.
Convert encoder to a dilated version for segmentation.
Update the encoder to accept a different number of input channels.
Attributes
Return output channel dimensions for encoder feature maps.
Return the effective output stride of the encoder.
- get_stages()[source]¶
Return encoder stages for dilation modification.
This method should be overridden by subclasses to provide stage mappings for converting strides to dilations.
- Returns:
Dictionary mapping output stride to corresponding module sequences.
- Return type:
dict[int, Sequence[torch.nn.Module]]
- Raises:
NotImplementedError – If the method is not implemented by the subclass.
Example
>>> stages = encoder.get_stages()
- make_dilated(output_stride)[source]¶
Convert encoder to a dilated version for segmentation.
- Parameters:
output_stride (int) – Target output stride (must be 8 or 16).
- Raises:
ValueError – If output_stride is not 8 or 16.
- Return type:
None
Example
>>> encoder.make_dilated(output_stride=16)
- property out_channels: list[int]¶
Return output channel dimensions for encoder feature maps.
Example
>>> encoder.out_channels ... [3, 32, 64, 128, 256, 512]
- property output_stride: int¶
Return the effective output stride of the encoder.
The output stride is the minimum of the configured stride and 2^depth.
- Returns:
Effective output stride.
- Return type:
Example
>>> encoder.output_stride ... 32