fix: stabilize DINO segmentation with global PCA and foreground-aware…#16
Merged
Conversation
… clustering Three structural issues caused wildly inconsistent spot counts across scans: - Per-slice PCA fitted different feature bases per slice, so HDBSCAN produced different cluster counts even for similar content - Background patches participated in PCA and clustering, diluting signal - min_cluster_size=3 allowed spurious micro-clusters Fixes: fit a single PCA across all foreground patches from all slices, mask out pure-background patches before clustering, raise min_cluster_size default 3→5, lower min_overlap_fraction 0.3→0.2. https://claude.ai/code/session_015Y9zQk4A8uKJAorKuvBoCk
The model name facebook/dinov3-vitb16-pretrain-lvd1689m is a real HuggingFace checkpoint (released 2025-08-13). Revert the incorrect rename to dinov2-small. Key fixes for the torch backend: - Skip register tokens (4 in DINOv3) when extracting patch features, not just the CLS token - Update default patch_size from 14 to 16 (DINOv3 uses 16x16 patches) - Read num_register_tokens from model config for forward compat Also update multiview encoder default model to DINOv3. https://claude.ai/code/session_015Y9zQk4A8uKJAorKuvBoCk
The comparison notebook now installs torch/transformers on Colab and uses backend="auto" so it runs real DINOv3 ViT-B/16 weights when a GPU is available, falling back to mock for local/CI environments. https://claude.ai/code/session_015Y9zQk4A8uKJAorKuvBoCk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… clustering
Three structural issues caused wildly inconsistent spot counts across scans:
Fixes: fit a single PCA across all foreground patches from all slices, mask out pure-background patches before clustering, raise min_cluster_size default 3→5, lower min_overlap_fraction 0.3→0.2.
https://claude.ai/code/session_015Y9zQk4A8uKJAorKuvBoCk