Cellpose-SAM (fastforks)

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.

This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/MouseLand/cellpose at a54cb48849b7.

Author weight repos: https://huggingface.co/mouseland/cellpose-sam.

Task: detection. Tier: experimental. Outputs: boxes, scores, labels, masks. Backends: portable, kernels.

Input: one RGB image. Output: boxes, class labels, scores and instance masks.

Variants

Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.

variant weights (author link) SHA-256 weights licence commercial use
cellpose-sam@1 cpsam e1440429eb38 BSD-3-Clause yes

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: BSD-3-Clause. Licence files: 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.

Licence evidence: https://huggingface.co/mouseland/cellpose-sam/blob/7c61431b5fbb078f3296754bd15d9f51b320f837/README.md (license: bsd-3-clause) ; https://github.com/MouseLand/cellpose/blob/a54cb48849b7e225a81e8e43dcb042d42427f543/LICENSE

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)

Speed and memory

Detection, synthetic

model input time (ms): original fp32 original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
cellpose-sam 2048x2048 – – – 2127 – – – – 1425 / 1558

Detection, Cellpose test images, 2048x2048

model time (ms): original fp32 original portable peak memory (MiB, allocated / reserved): original portable
cellpose-sam 9313 5948 3534 1577 / 2939 6922 / 8428

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
cellpose-sam 2.13 (2048x2048) 0.29 (2048x2048) 1.32 (677x677) 1.08 (2048x2048) 0.43 (2048x2048) 0.35 (677x677)

torch.compile and TensorRT

model input time: portable compile TensorRT (fp16 unless shown) kernels preparation: compile (cold first call) ONNX + engine build peak MiB (alloc / reserved): portable compile kernels TensorRT (engine + torch)
cellpose-sam 383x512 186 ms 144 ms fails: unsupported: torch.export stops at a data-dependent tensor c 146 ms 199 s – 799 / 1690 803 / 832 746 / 760 –

Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).

Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.

Accuracy

On public datasets

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

variant dataset original fp32 original fp16 portable portable fp32 note
cellpose-sam 2018 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.9 85.0 / 66.8 / 29.2 / 60.9 85.8 / 66.8 / 29.4 / 61.3 85.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 with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. 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).

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.

Usage

from fastforks import detection

model = detection.load("cellpose-sam")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.boxes, result.scores, result.labels  # [N, 4], [N], [N]
result.backend  # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')

Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: cellpose-sam.

Kernels backend

detection.load("cellpose-sam", mode="kernels") runs our CUDA kernels (cellpose_ops, dpt_fused). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for fastforks/cellpose-sam

Finetuned
(9)
this model