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| 3 |
+
pipeline_tag: image-segmentation
|
| 4 |
+
tags:
|
| 5 |
+
- pytorch
|
| 6 |
+
- segformer
|
| 7 |
+
- medical-imaging
|
| 8 |
+
- semantic-segmentation
|
| 9 |
+
- wavelet
|
| 10 |
+
- frequency-domain
|
| 11 |
+
- boundary-detection
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# WaveSeg
|
| 15 |
+
|
| 16 |
+
**WaveSeg** is a SegFormer-B0 backbone with a lightweight (770-parameter) **Frequency-Boundary
|
| 17 |
+
Adapter (FBA)** gating its decoder features via a Haar wavelet high-frequency branch. It is
|
| 18 |
+
evaluated on two 2D medical image segmentation domains: brain MRI lesion segmentation and polyp
|
| 19 |
+
segmentation.
|
| 20 |
+
|
| 21 |
+
**Locked configuration: WaveSeg = SegFormer-B0 + FBA frequency gating (ablation config A1), with
|
| 22 |
+
NO boundary-frequency auxiliary loss.** A boundary-frequency loss was also designed and tested at
|
| 23 |
+
several weights - it is reported as a **negative ablation** (see below), not part of the shipped
|
| 24 |
+
model.
|
| 25 |
+
|
| 26 |
+
## Task and datasets
|
| 27 |
+
|
| 28 |
+
- **Task:** binary semantic segmentation, 256x256 input.
|
| 29 |
+
- **Brain MRI (LGG):** FLAIR-abnormality segmentation on the `mateuszbuda/lgg-mri-segmentation`
|
| 30 |
+
dataset (Buda et al., *Computers in Biology and Medicine*, 2019) - 110 patients, 3,929 slices,
|
| 31 |
+
patient-level 70/15/15 split.
|
| 32 |
+
- **Polyp (Kvasir-SEG):** colonoscopy polyp segmentation on Kvasir-SEG (Jha et al., MMM 2020) -
|
| 33 |
+
1,000 images, 800/100/100 split.
|
| 34 |
+
|
| 35 |
+
## Results
|
| 36 |
+
|
| 37 |
+
All numbers below are read directly from `results/ablation_table_clean.csv` (grouped/averaged by
|
| 38 |
+
method+dataset across all completed runs - `n` is how many). Region metrics (Dice, mIoU,
|
| 39 |
+
Boundary-IoU) are higher-is-better; HD95/ASSD (pixel distances at 256x256) are lower-is-better.
|
| 40 |
+
|
| 41 |
+
### Brain MRI (LGG)
|
| 42 |
+
|
| 43 |
+
| Method | n | Dice | mIoU | Boundary-IoU | HD95 (px) | ASSD (px) | Params |
|
| 44 |
+
|---|---|---|---|---|---|---|---|
|
| 45 |
+
| SegFormer-B0 baseline (A0) | 3 | 0.8677 +/- 0.0103 | 0.9159 | 0.7898 | 29.70 | 27.07 | 3,714,401 |
|
| 46 |
+
| **WaveSeg (A1, ours)** | 2 | **0.8908 +/- 0.0055** | **0.9273** | **0.8112** | **22.83** | **20.56** | 3,715,171 |
|
| 47 |
+
|
| 48 |
+
### Kvasir-SEG (Polyp)
|
| 49 |
+
|
| 50 |
+
| Method | n | Dice | mIoU | Boundary-IoU | HD95 (px) | ASSD (px) | Params |
|
| 51 |
+
|---|---|---|---|---|---|---|---|
|
| 52 |
+
| SegFormer-B0 baseline (A0) | 1 | 0.9049 | 0.9038 | 0.5809 | 18.49 | 4.57 | 3,714,401 |
|
| 53 |
+
| **WaveSeg (A1, ours)** | 2 | **0.9103 +/- 0.0049** | **0.9084** | **0.5958** | **17.41** | **4.34** | 3,715,171 |
|
| 54 |
+
|
| 55 |
+
WaveSeg (A1) beats the SegFormer-B0 baseline on **every metric, on both datasets**, adding only
|
| 56 |
+
770 trainable parameters (3,715,171 vs 3,714,401).
|
| 57 |
+
|
| 58 |
+
## Honest negative ablation: the boundary-frequency loss does not help
|
| 59 |
+
|
| 60 |
+
The FBA module was originally paired with an auxiliary boundary-frequency loss (BCE+Dice
|
| 61 |
+
supervising the attention map toward the ground-truth mask's morphological-gradient edge). Tested
|
| 62 |
+
on LGG at `lambda_boundary` in {0.1, 0.25, 0.5, 1.0}, after seed-averaging (n>=2 where re-run):
|
| 63 |
+
|
| 64 |
+
| lambda_boundary | Dice (LGG) | Beats A1 (gating alone)? |
|
| 65 |
+
|---|---|---|
|
| 66 |
+
| 0.0 (= A1, shipped) | 0.8908 +/- 0.0055 | reference |
|
| 67 |
+
| 0.1 | 0.8826 +/- 0.0174 | no |
|
| 68 |
+
| 0.25 | 0.8727 | no |
|
| 69 |
+
| 0.5 | 0.8783 | no |
|
| 70 |
+
| 1.0 | 0.8753 +/- 0.0069 | no |
|
| 71 |
+
|
| 72 |
+
No tested weight improved on FBA gating alone. This is reported as a deliberate, honest negative
|
| 73 |
+
ablation rather than dropped: the frequency-domain gating mechanism is doing the work; explicitly
|
| 74 |
+
supervising its attention map toward GT edges does not add value at any weight tested. See the
|
| 75 |
+
training repository's `results/tables.md` and `CLAUDE.md` for the full ablation grid (A0-A5) and
|
| 76 |
+
the seed-confirmation methodology.
|
| 77 |
+
|
| 78 |
+
## Training details
|
| 79 |
+
|
| 80 |
+
- **Backbone:** `nvidia/mit-b0` (ImageNet-pretrained SegFormer-B0 encoder), fresh decode head.
|
| 81 |
+
- **Hardware:** local development/inference on an RTX 4060 (8GB); full training runs on Kaggle
|
| 82 |
+
T4/P100 and locally, all under an 8GB VRAM budget.
|
| 83 |
+
- **Precision:** AMP (mixed precision), channels-last memory format, batch size 16, 256x256 input.
|
| 84 |
+
- **Optimizer:** AdamW, lr 6e-5, weight decay 0.01, 100 epochs.
|
| 85 |
+
- **Reproducibility:** base seed 42 everywhere (data splits fixed across all seed variants);
|
| 86 |
+
multi-seed confirmation runs (seeds 42/123/456 depending on the row) give `n>=2` for every
|
| 87 |
+
number reported above except the two Kvasir/LGG A0 rows still at `n=1`.
|
| 88 |
+
- **Metrics:** Dice, mIoU (mean of foreground+background IoU), Boundary-IoU (Cheng et al., CVPR
|
| 89 |
+
2021), HD95 and ASSD (via `scipy.ndimage`; a fixed image-diagonal penalty is used for the
|
| 90 |
+
empty-mask edge case so every method aggregates over the identical image set).
|
| 91 |
+
|
| 92 |
+
## Intended use
|
| 93 |
+
|
| 94 |
+
Research and educational demonstration of frequency-domain gating for medical image segmentation
|
| 95 |
+
boundary quality. **Not validated for clinical use** - trained on two small public research
|
| 96 |
+
datasets (3,929 and 1,000 images respectively), with no independent multi-site validation.
|
| 97 |
+
|
| 98 |
+
## Limitations
|
| 99 |
+
|
| 100 |
+
- Both datasets are 2D, single-institution(-family) research collections; generalization to other
|
| 101 |
+
scanners, contrast protocols, or endoscopy hardware is untested.
|
| 102 |
+
- The `n=1` rows above (Kvasir/LGG A0 baseline on Kvasir) have no seed-variance estimate.
|
| 103 |
+
- The boundary-frequency loss's negative result was tested only on LGG and only up to
|
| 104 |
+
`lambda_boundary=1.0`; it does not rule out a different loss formulation working.
|
| 105 |
+
- Small lesions/polyps (a few hundred pixels) are the most common failure mode for both the
|
| 106 |
+
baseline and WaveSeg.
|
| 107 |
+
|
| 108 |
+
## How to use
|
| 109 |
+
|
| 110 |
+
See the project README for full reproduction instructions (training, evaluation, and the Gradio
|
| 111 |
+
demo). The demo Space loads these same weights: <https://huggingface.co/spaces/Sarvarbek13/WaveSeg-demo>.
|
| 112 |
+
|
| 113 |
+
## Citation
|
| 114 |
+
|
| 115 |
+
If you use this model, please cite the datasets and metrics it builds on:
|
| 116 |
+
|
| 117 |
+
```bibtex
|
| 118 |
+
@inproceedings{xie2021segformer,
|
| 119 |
+
title={SegFormer: Simple and efficient design for semantic segmentation with transformers},
|
| 120 |
+
author={Xie, Enze and Wang, Wenhai and Yu, Zhiding and Anandkumar, Anima and Alvarez, Jose M and Luo, Ping},
|
| 121 |
+
booktitle={Advances in Neural Information Processing Systems},
|
| 122 |
+
volume={34},
|
| 123 |
+
pages={12077--12090},
|
| 124 |
+
year={2021}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
@article{buda2019association,
|
| 128 |
+
title={Association of genomic subtypes of lower-grade gliomas with shape features automatically extracted by a deep learning algorithm},
|
| 129 |
+
author={Buda, Mateusz and Saha, Ashirbani and Mazurowski, Maciej A},
|
| 130 |
+
journal={Computers in Biology and Medicine},
|
| 131 |
+
volume={109},
|
| 132 |
+
pages={218--225},
|
| 133 |
+
year={2019},
|
| 134 |
+
publisher={Elsevier}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
@inproceedings{jha2020kvasir,
|
| 138 |
+
title={Kvasir-SEG: A segmented polyp dataset},
|
| 139 |
+
author={Jha, Debesh and Smedsrud, Pia H and Riegler, Michael A and Halvorsen, P{\aa}l and Lange, Thomas de and Johansen, Dag and Johansen, H{\aa}vard D},
|
| 140 |
+
booktitle={International Conference on Multimedia Modeling},
|
| 141 |
+
pages={451--462},
|
| 142 |
+
year={2020},
|
| 143 |
+
organization={Springer}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
@inproceedings{cheng2021boundary,
|
| 147 |
+
title={Boundary IoU: Improving object-centric image segmentation evaluation},
|
| 148 |
+
author={Cheng, Bowen and Girshick, Ross and Doll{\'a}r, Piotr and Berg, Alexander C and Kirillov, Alexander},
|
| 149 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
| 150 |
+
pages={15334--15342},
|
| 151 |
+
year={2021}
|
| 152 |
+
}
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
## Author
|
| 156 |
+
|
| 157 |
+
Sarvarbek Erniyazov. Licensed under the MIT License (see `LICENSE`).
|