feat(image): add MetaFormer encoder integration #4053
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(image): add MetaFormer encoder integration
Summary
Adds a new image encoder based on the MetaFormer family of architectures to Ludwig, enabling users to leverage a flexible token-mixing backbone for image feature extraction. Provides:
Motivation
MetaFormer-style backbones (e.g. ConvNeXt-like and token-mixing generalizations) offer competitive performance and architectural simplicity. This integration broadens Ludwig’s catalog of vision encoders and facilitates experimentation and benchmarking against existing CNN and ViT-style encoders.
Implementation Details
New Files
Modified Files
Testing
Test file tests/ludwig/encoders/test_metaformer_encoder.py covers:
The included miniature dataset ensures test reproducibility without external downloads.
Reproducibility
A small curated sample (test_data/) enables running:
pytest tests/ludwig/encoders/test_metaformer_encoder.py -k metaformer
(Works offline and fast.)
Usage Example
YAML snippet:
input_features:
type: image
encoder:
type: metaformer
variant: base # see metaformer_models.py for available variants
dropout: 0.1
output_features:
type: category
trainer:
epochs: 2
Backward Compatibility
No breaking changes. New encoder is opt-in. Existing image encoders unaffected.
Performance / Future Extensions
Issue Reference
If an issue exists, add a line such as:
Closes: #ISSUE_NUMBER
(Currently no explicit issue number provided.)
Checklist
Let me know if you would like the docs updated in this PR; otherwise this focuses on the core encoder integration and tests.