You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| **Augment padding on labels** | Mask propagated through augmentation | `RandAffined` reflection padding on labels → false affinities | Per-channel mask excludes border artifacts ✅ |
163
163
164
164
**Problem:** Two interacting issues caused border artifacts in affinity targets:
165
165
166
166
1. **Reflection padding on labels during augmentation**: `RandAffined`and `RandElasticd` use `padding_mode="reflection"` for all keys including labels. When spatial transforms rotate/scale/shear a patch, border pixels are filled with reflected label values. Computing affinity from these reflected labels creates false affinities — especially visible for long-range channels like ch11 (offset `0-27-0`) where the reflected region spans 27 voxels.
167
167
168
-
2. **Uniform spatial crop vs per-channel masking**: The old `deepem_crop` computed the **union** of all offsets' invalid borders and uniformly cropped all channels to this smallest valid region. For the SNEMI 12-channel offsets, this meant cropping (4, 27, 27) from all channels — even short-range channels that only need 1 voxel cropped. This wasted ~35% of training data for short-range channels.
168
+
2. **Uniform spatial crop vs per-channel masking**: The old crop path computed the **union** of all offsets' invalid borders and uniformly cropped all channels to this smallest valid region. For the SNEMI 12-channel offsets, this meant cropping (4, 27, 27) from all channels — even short-range channels that only need 1 voxel cropped. This wasted ~35% of training data for short-range channels.
169
169
170
170
**DeepEM's approach**: In DeepEM, `get_pair(arr, edge)` extracts two aligned crops per channel, computing affinity only in the overlap region. A separate mask (propagated through augmentation) excludes padded regions from the loss. Each channel has its own valid region.
Copy file name to clipboardExpand all lines: .claude/refactor/training.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ All 12 issues across 4 priority levels have been resolved. 190/191 unit tests pa
63
63
#### P3.2: Affinity decoupling in orchestrator.py
64
64
-**File**: `training/loss/orchestrator.py`
65
65
-**Issue**: Direct import of `data.process.affinity` created tight cross-package coupling
66
-
-**Fix**: Dependency injection via constructor parameters (`affinity_crop_enabled_fn`, `crop_spatial_fn`, `resolve_affinity_offsets_fn`) with lazy-import bridge functions as defaults. No behavioral change
66
+
-**Fix**: Dependency injection via constructor parameters (`resolve_affinity_mode_fn`, `resolve_affinity_offsets_fn`) with lazy-import bridge functions as defaults. Affinity target handling now routes through explicit `affinity_mode`.
67
67
68
68
#### P3.3: Logging migration (print -> logging)
69
69
-**Files**: All files in `training/` except `debugging.py`
0 commit comments