Commit 6644898
Add NaViT: Native Resolution Vision Transformer with Patch n' Pack (#9011)
Adds NaViT (monai.networks.nets.NaViT), a Vision Transformer that
removes the fixed-resolution constraint of standard ViT by packing
multiple variable-size images into a single sequence per batch element.
Key features:
- Patch n' Pack: multiple images concatenated into one sequence per
group, with a per-image attention mask preventing cross-image attention
- Factorised positional embeddings: separate learnable tables per
spatial axis, allowing generalisation to unseen resolutions
- Token dropout: configurable fraction of patch tokens dropped during
training (float or callable)
- Attention pooling: learned query attends over each image's tokens to
produce a fixed-size per-image representation
- QK normalisation: RMS normalisation on queries and keys (ViT-22B
style)
- 2D and 3D support: works for (C, H, W) and (C, H, W, D) inputs
Changes:
- monai/networks/nets/navit.py: new NaViT implementation
- monai/networks/nets/__init__.py: export NaViT
- tests/networks/nets/test_navit.py: 24 unit tests covering shape,
variable resolutions, token dropout, auto-grouping, gradient flow, ill
arguments, and forward validation
- docs/source/networks.rst: autoclass entry
- docs/source/whatsnew_1_5_2.md: feature description
- CHANGELOG.md: entry under Unreleased
Fixes # .
### Description
A few sentences describing the changes proposed in this pull request.
### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.
---------
Signed-off-by: Vikash Gupta <write2vikash@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>1 parent 7f6bf2d commit 6644898
6 files changed
Lines changed: 826 additions & 0 deletions
File tree
- docs/source
- monai/networks/nets
- tests
- networks/nets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
665 | 670 | | |
666 | 671 | | |
667 | 672 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
0 commit comments