Tags: alxndrkalinin/cubic
Tags
Support all Cellpose v4 models (SAM + DINO) in GPU-resident segmentat… …ion (#51) * feat(segmentation): support all Cellpose v4 models in GPU-resident path Rename the GPU-resident entry point to segment_cellpose and cover every Cellpose v4 model -- the SAM backbone (cpsam, cpsam_v2) and the DINOv3 backbones (cpdino, cpdino-vitb). The backbones differ only in the default tile size (256 for sam_vitl, 384 for dino_*) and share the (flow, style) forward contract, so the resident path needs only to expose bsize and thread it through _run_net_gpu, with cellpose's sam_vitl->256 guard. segment_cpsam is kept as a deprecated alias (warns, slated for removal after 0.8). Parity tests confirm resident masks match stock CellposeModel.eval (AP >= 0.95) for all four models in 2D and 3D. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(deps): add cellpose-dino extra and require cellpose>=4.2.0 The DINO models (cpdino, cpdino-vitb) and cpsam_v2 first ship in cellpose 4.2.0, and the DINO backbones additionally need the dinov3 dependency from cellpose's `dino` extra. Bump the base cellpose extra to >=4.2.0 and add a cellpose-dino extra (cubic[cellpose] + cellpose[dino]>=4.2.0), documenting both install paths in the README. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * refactor(segmentation): centralize backbone tile-size resolution The default tile size (256 for SAM, 384 for DINO) and the SAM-pinned-to-256 guard were encoded separately in _run_net_gpu and segment_cellpose -- two sources of truth for the same backbone->tile-size rule. Extract _resolve_bsize to own both; segment_cellpose resolves bsize once and passes the concrete value down, so _run_net_gpu no longer needs the backbone argument. Replace the GPU-only bsize-guard test with a fast pure-function unit test that covers the full resolution matrix (defaults per backbone + the SAM guard), removing a heavyweight model load for a string-compare assertion. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test(segmentation): share CellposeModel instances across tests The GPU parity tests each constructed their own CellposeModel, reloading the same weights repeatedly (cpsam alone was built ~8 times). Add a module-scoped factory fixture that caches one model per backbone and route every GPU test through it. eval/segment_cellpose are read-only inference, so a shared instance is safe; the fixture is lazy, so no-GPU/no-cellpose runs never construct a model and free VRAM on teardown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore: bump version to 0.8.0a1 First alpha of the 0.8 cycle, which adds DINO-model support to the GPU-resident segmentation path and deprecates segment_cpsam. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(segmentation): mention DINO in _require_cellpose error message The ImportError raised when cellpose is missing still said "(SAM)" only, while _check_gpu_precondition was already updated to "(SAM or DINO)". Align the message and point DINO users at the dinov3 install note in the README. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(deps): drop unusable cellpose[dino] extra; document dinov3 install Published cellpose (4.2.1.1) does not expose a `dino` extra, and dinov3 is git-only (pip install git+https://github.com/facebookresearch/dinov3), so it cannot be declared as a dependency of a PyPI package. The cellpose-dino extra therefore pulled no dinov3 (uv warned the extra did not exist). Remove it and document the manual dinov3 install in the README for the DINO backbones. Regenerate uv.lock, which was stale against the cellpose>=4.2.0 bump (it still recorded >=4.0 and resolved cellpose 4.1.1, predating cpsam_v2/cpdino). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(segmentation): reject non-positive bsize for DINO backbones bsize is now part of the public segment_cellpose API, but _resolve_bsize passed any explicit value straight through for DINO backbones, so bsize<=0 reached make_tiles/run_net_gpu and caused divide-by-zero / invalid tiling. Validate it as a positive integer and fail fast with a clear error. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Alexandr Kalinin <alxndrkalinin@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
PreviousNext