Models · Object detection

Cellpose-SAM

Cellpose-SAM (HHMI Janelia, 2025): one mask per cell or nucleus in 2D microscopy images (fluorescence, brightfield, tissue, bacteria), no channel or size settings. BSD-3 code and weights (commercial use allowed); some training datasets are CC-BY-NC.

experimental Fork of MouseLand/cellpose@a54cb48 · backends: portable, kernels

Checkpoint cellpose-sam

Paper 2025 Added in 0.4.0 Evaluated with 0.4.0

Kernels, RTX 5060 Ti 16 GB 2127 ms 2048x2048, fp16
vs the faster original 2.8× original bf16: 5948 ms
Peak memory 1,425 MiB original: 1,577 MiB
Accuracy vs original fp32 +0.8 portable ap50, 2018 Data Science Bowl nuclei (134 stage1_train images) (85.0 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install fastforks-core

from fastforks import detection

model = detection.load("cellpose-sam")  # fastest backend that runs here
result = model("photo.jpg", score_threshold=0.5)

# result fields: boxes, scores, labels, masks
boxes = result.boxes  # a torch tensor
arrays = result.numpy()  # the tensor fields as NumPy arrays: arrays["boxes"]
result.backend  # what ran: mode, device, dtype
Other ways to run it
  • Backend: detection.load("cellpose-sam", mode="kernels") # or "portable", "auto" (default)
  • Precision: detection.load("cellpose-sam", dtype="float32") # full precision: slower, portable only
  • Options: detection.load("cellpose-sam", options={"flow_threshold": 0.4, "cellprob_threshold": 0, "min_size": 15, "score_threshold": 0})
fastforks bench cellpose-sam

Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.

Speed and memory

Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32MouseLand/cellpose@a54cb48849b7 CellposeModel(use_bfloat16=False).eval, TF32 on (cellpose's own setting)fp32 93130.64×3,072 MiB/5,315 MiB2.51.34
Original (own default)the authors' use_bfloat16 option (their default); MouseLand/cellpose@a54cb48849b7 CellposeModel.evalbf16 5948–1,577 MiB/2,939 MiB2.11.08
Portable fp32fp32not measured ––––
Portablefp16 35341.7×6,922 MiB/8,428 MiB0.30.43
Kernelsfp16 21272.8×1,425 MiB/1,558 MiB1.32.13
Portable + torch.compilenot measured here ––––
TensorRTnot measured here ––––

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-28 to 2026-12-02. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.

Other devices

Not measured on other devices yet.

Licence and weights

Commercial use allowed

Code
BSD-3-Clause LICENSE
Weights
BSD-3-Clause source
Training data
  • Code and weights are BSD-3-Clause (commercial use allowed), but the training set includes non-commercial data (LIVECell CC-BY-NC-4.0, TissueNet, the Cellpose dataset); check whether that matters for your use.

Our reading of the licences, not legal advice.

Weights

cpsam 1.2 GB· hosted on Hugging Face

fastforks downloads and checks these files on first use (fastforks download cellpose-sam).

Accuracy

The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.

2018 Data Science Bowl nuclei (134 stage1_train images)

AP at IoU 0.5 / 0.75 / 0.9 / mean over 0.5-0.95 %

Rundtypeap50 ↑ap75 ↑ap90 ↑dsb ↑Δ ap50 vs fp32 originalimagesms / image
Original fp32fp3285.066.829.060.9 reference 134 334
Original fp16bf1685.066.829.260.9 −0.1 134 199
Portable fp32fp3285.866.829.461.2 +0.8 134 305
Portablefp1685.866.829.461.3 +0.8 134 122
Kernelsnot measured

pycocotools COCOeval of the top 100 detections per image. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-30; portable fp32, portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks d5364b118, 2026-11-30.

Closeness to the original

Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output boxes).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.002 not recorded
GPU default dtypes, mean |diff|≤ 0.02 0
GPU default dtypes, p99 |diff|≤ 0.25 0

Recorded for cellpose-sam on RTX 5060 Ti, torch 2.14.1+cu130, 2026-12-02, with these kernels: cellpose_opsdpt_fused

Details

Cellpose-SAM (Pachitariu, Rariden and Stringer 2025, MouseLand / HHMI Janelia): cell and nucleus instance segmentation of 2D microscopy images (fluorescence, brightfield, phase contrast, tissue, bacteria), one generalist model with no channel or diameter settings. A SAM ViT-L encoder at patch 8 predicts per-pixel flows towards each cell centre and a cell probability on 256 x 256 tiles; following the flows groups the pixels into cells. Returns one instance (`cell`) per cell: its mask at the input size, its box and the mean cell probability as score.

Input / output
Input: one RGB image. Output: boxes, class labels, scores and instance masks.
Input size
any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (4,222 MiB allocated)
Options
  • flow_threshold=0.4>= 0.0· changes the output
  • cellprob_threshold=0-6.0 to 6.0· changes the output
  • min_size=15>= 0· changes the output
  • score_threshold=00.0 to 1.0· changes the output
Outputs
boxes, scores, labels, masks
CUDA kernels
  • cellpose_ops
  • dpt_fusedfused fp16 matrix multiplies and convolutions for DINOv2 backbones and DPT depth heads
Apple (MPS)
fp32, fp16, bf16

Limitations

  • Training data includes non-commercial (CC-BY-NC) datasets; the weights themselves are BSD-3-Clause.
  • 2D only, no diameter rescale and no test-time augmentation (upstream `eval` defaults: diameter None, niter 200). Very small or very large cells (outside roughly 7 to 100 px diameter) segment worse; rescale the image first.
  • Masks are dense `[N, H, W]` booleans, N x H x W bytes: about 1 GB for 250 cells in a 2048 x 2048 image. For very many cells, tile the image yourself.
  • `kernels` (CUDA) speeds up only the tile network (attention without a dense bias mask, fused GEMM epilogues: 8 tiles 216 -> 164 ms on an RTX 5060 Ti); flow following and masks run as in `portable`.
  • On Apple MLX the tile network runs hand-written in float16 or float32; the tiling, flow following and masks run in PyTorch on the CPU.
Full reference, generated from the repository

Cellpose-SAM (HHMI Janelia, 2025): one mask per cell or nucleus in 2D microscopy images (fluorescence, brightfield, tissue, bacteria), no channel or size settings. BSD-3 code and weights (commercial use allowed); some training datasets are CC-BY-NC.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
cellpose-samCellpose test images (2048x2048)original (fp32)
original
portable
kernels
9313
5948
3534
2127
3072 / 5315
1577 / 2939
6922 / 8428
1425 / 1558
cellpose-samCellpose test images (383x512)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
492
294
186
146
144
fails: unsupported: torch.export stops at a data-dependent tensor c
2570 / 5315
1300 / 2683
799 / 1690
746 / 760
803 / 832
–
Details
  • Original code: https://github.com/MouseLand/cellpose at a54cb48849b7
  • Code licence: BSD-3-Clause (permissive); files: LICENSE
  • Weights licence: BSD-3-Clause
  • Licence evidence: https://huggingface.co/mouseland/cellpose-sam/blob/7c61431b5fbb078f3296754bd15d9f51b320f837/README.md (license: bsd-3-clause) ; https://github.com/MouseLand/cellpose/blob/a54cb48849b7e225a81e8e43dcb042d42427f543/LICENSE
  • Training data: Cellpose-SAM training set: Cellpose (cyto2, nuclei), TissueNet, LIVECell, Omnipose, DeepBacs, YeaZ and the NeurIPS 2022 cell-segmentation challenge (Ma et al. 2024); the encoder was initialised from SAM (SA-1B) (About 22k images from Cellpose, TissueNet, LIVECell, Omnipose, DeepBacs, YeaZ and the NeurIPS 2022 challenge (paper); several are non-commercial. The encoder was initialised from SAM ViT-L.)
  • Licence note: Code and weights are BSD-3-Clause (commercial use allowed), but the training set includes non-commercial data (LIVECell CC-BY-NC-4.0, TissueNet, the Cellpose dataset); check whether that matters for your use.
  • Options: flow_threshold = 0.4 (>= 0.0), cellprob_threshold = 0.0 (-6.0 to 6.0), min_size = 15 (>= 0), score_threshold = 0.0 (0.0 to 1.0)
  • Kernel libraries: cellpose_ops, dpt_fused
  • Variants: cellpose-sam
  • Outputs: boxes, scores, labels, masks; label_set: cell-1
  • Input size: any H x W >= 32, padded to a multiple of 32
  • Tested up to (portable, fp16, RTX 5060 Ti 16 GB): cellpose-sam 3000x4000 (4.1 GiB peak allocated, 5.4 reserved)
  • cellpose-sam 383x512, first call: portable + torch.compile 199 s (cold Inductor cache).
  • cellpose-sam original (fp32) 2048x2048, original (fp32) 383x512: MouseLand/cellpose@a54cb48849b7 CellposeModel(use_bfloat16=False).eval, TF32 on (cellpose's own setting)
  • cellpose-sam original 2048x2048, original 383x512: the authors' use_bfloat16 option (their default); MouseLand/cellpose@a54cb48849b7 CellposeModel.eval
  • cellpose-sam load / first call: original 2.13 s / 1.08 s (2048x2048), portable 0.29 s / 0.43 s (2048x2048), kernels 1.32 s / 0.355 s (677x677)
  • Protocol, median of 10 (2048x2048: 5) after 1 warm-up, float CUDA input, card defaults (instances with dense masks out); peak = max over the timed calls (reserved carries over from the smaller image before); load / first call: per process, first call on gray_2D

Measured

pycocotools COCOeval of the top 100 detections per image. Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32original fp16portableportable fp32note
cellpose-sam2018 Data Science Bowl nuclei (134 stage1_train images), AP at IoU 0.5 / 0.75 / 0.9 / mean over 0.5-0.95 %85.0 / 66.8 / 29.0 / 60.985.0 / 66.8 / 29.2 / 60.985.8 / 66.8 / 29.4 / 61.385.8 / 66.8 / 29.4 / 61.2

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks d5364b118, 2026-11-30.

Parity

CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output boxes).

variantkernels error vs original, mean / p99GPU, torchkernels used
cellpose-sam0.0 / 0.0RTX 5060 Ti, torch 2.14.1+cu130cellpose_ops@a099e7658cdc:sm_120, dpt_fused@48e0065bb7cf:sm_120

Limitations

  • Training data includes non-commercial (CC-BY-NC) datasets; the weights themselves are BSD-3-Clause.
  • 2D only, no diameter rescale and no test-time augmentation (upstream eval defaults: diameter None, niter 200). Very small or very large cells (outside roughly 7 to 100 px diameter) segment worse; rescale the image first.
  • Masks are dense [N, H, W] booleans, N x H x W bytes: about 1 GB for 250 cells in a 2048 x 2048 image. For very many cells, tile the image yourself.
  • kernels (CUDA) speeds up only the tile network (attention without a dense bias mask, fused GEMM epilogues: 8 tiles 216 -> 164 ms on an RTX 5060 Ti); flow following and masks run as in portable.
  • On Apple MLX the tile network runs hand-written in float16 or float32; the tiling, flow following and masks run in PyTorch on the CPU.

Example output

No example rendered for this checkpoint yet.