timm_efficientnet

EfficientNet Encoder Implementation using timm.

This module provides an implementation of EfficientNet-based encoders for use in semantic segmentation and other computer vision tasks. It leverages the timm library for model components and adds encoder-specific functionality such as custom input channels, dilation support, and configurable scaling parameters.

Key Components:

  • patch_first_conv:

    Utility to modify the first convolution layer for arbitrary input channels.

  • replace_strides_with_dilation:

    Utility to convert strides into dilations for atrous convolutions.

  • EncoderMixin:

    Mixin class adding encoder-specific features like output channels and stride.

  • EfficientNetBaseEncoder:

    Base encoder combining EfficientNet backbone with encoder functionality.

  • EfficientNetEncoder:

    Configurable EfficientNet encoder supporting depth and channel scaling.

  • timm_efficientnet_encoders:

    Dictionary of available EfficientNet encoder configurations and pretrained settings.

Features:

  • Supports arbitrary input channels (e.g., grayscale or multi-channel images).

  • Allows conversion to dilated versions for semantic segmentation.

  • Provides pretrained weights from multiple sources (ImageNet, AdvProp, Noisy Student).

  • Implements scaling rules for EfficientNet architecture.

Example

>>> from tiatoolbox.models.architecture.timm_efficientnet import EfficientNetEncoder
>>> encoder = EfficientNetEncoder(
...     stage_idxs=[2, 3, 5],
...     out_channels=[3, 32, 24, 40, 112, 320],
...     channel_multiplier=1.0,
...     depth_multiplier=1.0,
...     drop_rate=0.2
... )
>>> x = torch.randn(1, 3, 224, 224)
>>> features = encoder(x)
>>> [f.shape for f in features]
[torch.Size([1, 3, 224, 224]), torch.Size([1, 32, 112, 112]), ...]

References

  • Tan, Mingxing, and Quoc V. Le. “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks.” arXiv preprint arXiv:1905.11946 (2019). URL: https://arxiv.org/abs/1905.11946

Functions

get_efficientnet_kwargs

Generate configuration parameters for EfficientNet.

patch_first_conv

Update the first convolution layer for a new input channel size.

replace_strides_with_dilation

Replace strides with dilation in Conv2d layers.

Classes

EfficientNetBaseEncoder

Base class for EfficientNet encoder.

EfficientNetEncoder

EfficientNet encoder with configurable scaling parameters.

EncoderMixin

Mixin class adding encoder-specific functionality.