Skip to content

🆕 Add SegFormer Architecture#1085

Open
Jiaqi-Lv wants to merge 6 commits into
developfrom
add-segformer
Open

🆕 Add SegFormer Architecture#1085
Jiaqi-Lv wants to merge 6 commits into
developfrom
add-segformer

Conversation

@Jiaqi-Lv

@Jiaqi-Lv Jiaqi-Lv commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

This pull request adds SegFormer segmentation model, and refactors the EfficientUNetTissueMaskModel to use shared utility modules for common layers.

New architectures for semantic segmentation

SegFormer
Mix Transformer (Encoder)

Refactoring for code reuse

  • Refactors EfficientUNetTissueMaskModel to use the shared Conv2dReLU and SegmentationHead implementations from architecture.utils, replacing local definitions and reducing code duplication. [1] [2] [3] [4] [5]

@Jiaqi-Lv Jiaqi-Lv self-assigned this Jun 29, 2026
@Jiaqi-Lv Jiaqi-Lv added the enhancement New feature or request label Jun 29, 2026
@Jiaqi-Lv Jiaqi-Lv changed the title Add SegFormer Architecture 🆕 Add SegFormer Architecture Jun 29, 2026
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.89%. Comparing base (1c94d65) to head (d6f98a7).

Additional details and impacted files
@@            Coverage Diff            @@
##           develop    #1085    +/-   ##
=========================================
  Coverage    99.88%   99.89%            
=========================================
  Files           86       88     +2     
  Lines        11661    11962   +301     
  Branches      1531     1549    +18     
=========================================
+ Hits         11648    11949   +301     
  Misses           7        7            
  Partials         6        6            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shaneahmed shaneahmed added this to the Release v2.1.3 milestone Jun 30, 2026
@Jiaqi-Lv Jiaqi-Lv marked this pull request as ready for review July 5, 2026 21:53
@Jiaqi-Lv Jiaqi-Lv requested a review from shaneahmed July 5, 2026 22:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new transformer-based semantic segmentation architecture (SegFormer) backed by a Mix Transformer encoder, while refactoring existing segmentation architectures to reuse shared utility layers (e.g., Conv2dReLU, SegmentationHead, encoder utilities).

Changes:

  • Add new SegFormer model implementation and a Mix Transformer (MiT) encoder backbone.
  • Centralize shared encoder and convolution utilities in architecture.utils and remove duplicated implementations.
  • Add/adjust unit tests for the new architecture and for the moved utility functions.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
tiatoolbox/models/architecture/utils.py Adds shared building blocks (Conv2dReLU, EncoderMixin, dilation/patching utilities) used across architectures.
tiatoolbox/models/architecture/timm_efficientnet.py Refactors EfficientNet encoder to import shared encoder mixin utilities instead of local copies.
tiatoolbox/models/architecture/segformer.py Adds SegFormer model + decoder and inference/pre/post-processing helpers.
tiatoolbox/models/architecture/mix_transformer.py Adds Mix Transformer backbone/encoder implementation used by SegFormer.
tiatoolbox/models/architecture/grandqc.py Replaces local Conv2dReLU with the shared implementation from architecture.utils.
tiatoolbox/models/architecture/efficientunet_tissue_mask_model.py Refactors to use shared Conv2dReLU and SegmentationHead from architecture.utils.
tests/models/test_arch_utils.py Adds tests for moved utilities (patch_first_conv, replace_strides_with_dilation).
tests/models/test_arch_timm_efficientnet.py Removes tests that moved to test_arch_utils.py.
tests/models/test_arch_segformer.py Adds unit tests covering SegFormer model, decoder behavior, and preprocessing/postprocessing/inference.
tests/models/test_arch_mix_transformer.py Adds unit tests for Mix Transformer backbone + encoder behaviors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tiatoolbox/models/architecture/utils.py
Comment thread tiatoolbox/models/architecture/utils.py
Comment thread tiatoolbox/models/architecture/utils.py Outdated
Comment thread tiatoolbox/models/architecture/mix_transformer.py
Comment thread tiatoolbox/models/architecture/mix_transformer.py
Comment thread tiatoolbox/models/architecture/segformer.py
Comment thread tiatoolbox/models/architecture/segformer.py
Comment thread tiatoolbox/models/architecture/segformer.py
Comment thread tiatoolbox/models/architecture/mix_transformer.py Outdated
Comment thread tiatoolbox/models/architecture/mix_transformer.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants