Commit 4ac3050
Modularizing the model's folder (#365)
* add planning roadmap
* docs: start milestone v1.1 Models
* docs: define milestone v1.1 requirements
* docs: create milestone v1.1 roadmap (5 phases)
* docs(package-scaffold-shared-components): research phase domain
* docs(06): create phase plan - package scaffold and shared components
* feat(06-01): create viscy-models package scaffold
- Add pyproject.toml with hatchling build, torch/timm/monai/numpy deps
- Create src layout with _components, unet, contrastive, vae subpackages
- Add PEP 561 py.typed marker
- Add test scaffolding with device fixture
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(06-01): register viscy-models in workspace
- Add viscy-models to root dependencies and uv sources
- Update lockfile with timm and viscy-models dependencies
- Verified: uv sync, import, and pytest collection all succeed
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(06-01): complete package scaffold plan
- Add 06-01-SUMMARY.md with execution results
- Update STATE.md with position, metrics, and decisions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(06-02): extract shared components into _components/ module
- stems.py: UNeXt2Stem, StemDepthtoChannels from v0.3.3 unext2.py
- heads.py: PixelToVoxelHead, UnsqueezeHead, PixelToVoxelShuffleHead
- blocks.py: icnr_init, _get_convnext_stage, UNeXt2UpStage, UNeXt2Decoder
- __init__.py: re-exports all 8 public components
- Zero imports from unet/, vae/, or contrastive/
- All attribute names preserved for state dict compatibility
* feat(06-03): migrate ConvBlock2D and ConvBlock3D to unet/_layers/
- Copy ConvBlock2D from v0.3.3 source to snake_case file
- Copy ConvBlock3D from v0.3.3 source to snake_case file
- Preserve register_modules/add_module pattern for state dict key compatibility
- Update _layers/__init__.py with public re-exports
- Fix docstring formatting for ruff D-series compliance
* test(06-03): add tests for ConvBlock2D and ConvBlock3D
- 6 tests for ConvBlock2D: forward pass, state dict keys, residual, filter steps, instance norm
- 4 tests for ConvBlock3D: forward pass, state dict keys, dropout registration, layer order
- All 10 tests verify shape, naming patterns, and module registration
* test(06-02): add forward-pass tests for all _components
- test_stems.py: UNeXt2Stem shape, StemDepthtoChannels shape + mismatch error
- test_heads.py: PixelToVoxelHead, UnsqueezeHead, PixelToVoxelShuffleHead shapes
- test_blocks.py: icnr_init, _get_convnext_stage, UNeXt2UpStage, UNeXt2Decoder
- 10 tests total, all passing on CPU
* docs(06-03): complete UNet ConvBlock layers plan
- SUMMARY.md with migration details and self-check
- STATE.md updated: phase 6 plan 3/3, decisions recorded
* docs(06-02): complete shared components extraction plan
- SUMMARY.md documents 8 extracted components with 10 tests
- STATE.md updated with decisions from 06-02 execution
* docs(phase-6): complete phase execution and verification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(07-core-unet-models): research phase domain
* docs(07): create phase plan for core UNet models
* feat(07-01): migrate UNeXt2 model class to viscy-models
- Copy UNeXt2 class (~70 lines) from monolithic unext2.py
- Update imports to use viscy_models._components (stems, heads, blocks)
- Preserve all attribute names for state dict compatibility
- Export UNeXt2 from viscy_models.unet public API
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test(07-01): add 6 UNeXt2 forward-pass tests and fix deconv tuple bug
- Add tests: default, small backbone, multichannel, diff stack depths, deconv, stem validation
- Fix deconv decoder tuple bug in UNeXt2UpStage (trailing comma created tuple not module)
- Mark deconv test xfail: original code has channel mismatch in deconv forward path
- All 26 tests pass (25 passed, 1 xfailed) with no regressions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(07-01): complete UNeXt2 migration plan
- Add 07-01-SUMMARY.md with execution results and deviation documentation
- Update STATE.md: phase 7, plan 1/2 complete, new decisions logged
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(07-02): migrate FullyConvolutionalMAE to viscy-models
- Copy FCMAE and all helper classes/functions to unet/fcmae.py
- Replace old viscy imports with viscy_models._components imports
- Remove duplicated PixelToVoxelShuffleHead (import from _components.heads)
- Fix mutable list defaults to tuples (encoder_blocks, dims)
- Export both UNeXt2 and FullyConvolutionalMAE from unet/__init__.py
* test(07-02): migrate 11 FCMAE tests to viscy-models
- Copy all 11 test functions with zero logic changes
- Update imports from viscy.unet.networks.fcmae to viscy_models.unet.fcmae
- Import PixelToVoxelShuffleHead from viscy_models._components.heads
- All 37 tests pass across full suite (no regressions)
* docs(07-02): complete FCMAE migration plan (Phase 7 complete)
- Add 07-02-SUMMARY.md with execution results
- Update STATE.md: Phase 7 complete, 12 plans total, decisions logged
* docs(phase-7): complete phase execution and verification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(phase-8): research representation models migration
* docs(08): create phase plan for representation models
* feat(08-02): migrate BetaVae25D and BetaVaeMonai to viscy-models
- Add BetaVae25D with VaeUpStage, VaeEncoder, VaeDecoder helpers
- Add BetaVaeMonai wrapping MONAI VarAutoEncoder
- Fix VaeDecoder mutable list defaults to tuples (COMPAT-02)
- Change VaeEncoder pretrained default to False
- Preserve all attribute names for state dict compatibility
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(08-01): migrate ContrastiveEncoder and ResNet3dEncoder to viscy-models
- Add ContrastiveEncoder with convnext/resnet50 backbone support via timm
- Add ResNet3dEncoder with MONAI ResNetFeatures backend
- Fix ResNet50 bug: use encoder.num_features instead of encoder.head.fc.in_features
- Add pretrained parameter (default False) for pure nn.Module semantics
- Preserve state dict attribute names (stem, encoder, projection)
- Share projection_mlp utility between both encoder classes
* test(08-01): add 5 forward-pass tests for contrastive models
- 3 tests for ContrastiveEncoder: convnext_tiny, resnet50, custom stem
- 2 tests for ResNet3dEncoder: resnet18, resnet10
- Verify embedding and projection output shapes
- ResNet50 test uses in_stack_depth=10 for valid stem channel alignment
* test(08-02): add forward-pass tests for BetaVae25D and BetaVaeMonai
- 2 BetaVae25D tests: resnet50 and convnext_tiny backbones
- 2 BetaVaeMonai tests: 2D and 3D spatial configurations
- Verify SimpleNamespace output with recon_x, mean, logvar, z
- Fix ResNet50 expected spatial dims (64x64 not 128x128)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(08-01): complete contrastive model migration plan
- Add 08-01-SUMMARY.md with execution results
- Update STATE.md to Phase 8, plan 1/2
* docs(08-02): complete VAE migration plan (Phase 8 complete)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(phase-8): complete phase execution and verification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(09): research legacy UNet models migration
* docs(09): create phase plan for legacy UNet models
* feat(09-01): migrate Unet2d and Unet25d to viscy-models
- Copy Unet2d from v0.3.3 with import path update to viscy_models.unet._layers
- Copy Unet25d from v0.3.3 with import path update to viscy_models.unet._layers
- Fix mutable default num_filters=[] to num_filters=() in both models
- Add module docstrings and __all__ exports
- Update unet/__init__.py to export all 4 models (UNeXt2, FCMAE, Unet2d, Unet25d)
- Preserve register_modules/add_module pattern for state dict compatibility
- All 45 existing tests still pass
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test(09-01): add pytest tests for Unet2d and Unet25d
- 12 tests for Unet2d: default forward, variable depth, multichannel, residual,
task mode, dropout, state dict keys, custom num_filters
- 11 tests for Unet25d: default Z-compression, preserved depth, variable depth,
multichannel, residual, task mode, state dict keys with skip_conv_layer, custom filters
- Fix list(num_filters) conversion in both models for tuple default compatibility
- Total test suite: 68 passed, 1 xfailed, 0 failures
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(09-01): complete legacy UNet migration plan
- SUMMARY.md with task commits, deviations, and self-check
- STATE.md updated to Phase 9 complete (15 plans total)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(phase-9): complete phase execution and verification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(10): create phase plan for public API and CI integration
* feat(10-01): add top-level re-exports for all 8 model classes
- Import UNeXt2, FullyConvolutionalMAE, Unet2d, Unet25d from unet subpackage
- Import ContrastiveEncoder, ResNet3dEncoder from contrastive subpackage
- Import BetaVae25D, BetaVaeMonai from vae subpackage
- Update __all__ with all 8 classes in alphabetical order
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test(10-01): add state dict key compatibility regression tests
- 24 tests covering all 8 migrated model architectures
- Each model tested for parameter count, top-level prefixes, and sentinel keys
- Guards COMPAT-01: state dict keys must match for checkpoint loading
- Tests import from top-level viscy_models package (validates public API)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore(10-01): add viscy-models to CI test matrix
- Add package dimension to test matrix (viscy-transforms, viscy-models)
- Use cross-platform --cov=src/ instead of named package coverage
- Matrix now produces 18 jobs (3 OS x 3 Python x 2 packages)
- check job automatically aggregates all test results via alls-green
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(10-01): complete public API & CI integration plan (v1.1 milestone complete)
- Add 10-01-SUMMARY.md with execution results
- Update STATE.md: phase 10 complete, v1.1 milestone done, 100% progress
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs(phase-10): complete phase execution and verification (v1.1 milestone complete)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor: consolidate ConvBlock2D/3D into _components
Move conv_block_2d.py and conv_block_3d.py from unet/_layers/ to
_components/ alongside all other shared building blocks. All reusable
layers now live in one place. unet/_layers/ retained as backward-
compatible re-export shim.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* remove the _layers
* update the readme
* update the main readme
* fix description in toml
* changing ruff formatting , dosctrings and imports
* renaming folder to components
* updatet planning docs
* update to components
* numpy docstring
* add claude.md and contributing.md
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 12b0279 commit 4ac3050
113 files changed
Lines changed: 18145 additions & 65 deletions
File tree
- .github/workflows
- .planning
- phases
- 01-workspace-foundation
- 02-package-structure
- 03-code-migration
- 04-documentation
- 05-ci-cd
- 07-core-unet-models
- 08-representation-models
- 09-legacy-unet-models
- 10-public-api-ci-integration
- research
- packages/viscy-models
- src/viscy_models
- components
- contrastive
- unet
- vae
- tests
- test_components
- test_contrastive
- test_unet
- test_vae
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
40 | | - | |
| 40 | + | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
0 commit comments