keejkrej commited on
Commit
7718902
·
verified ·
1 Parent(s): f01bcea

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. README.md +88 -0
  3. model.onnx +3 -0
  4. model.onnx.data +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.onnx.data filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: bsd-3-clause
3
+ license_name: bsd-3-clause-code-cc-by-nc-data
4
+ library_name: onnx
5
+ tags:
6
+ - cellpose
7
+ - cell-segmentation
8
+ - microscopy
9
+ - onnx
10
+ - biology
11
+ pipeline_tag: image-segmentation
12
+ ---
13
+
14
+ # Cellpose cpsam — ONNX
15
+
16
+ ONNX export of the [Cellpose](https://github.com/MouseLand/cellpose) **cpsam** (Cellpose-SAM) model for cell segmentation in microscopy images.
17
+
18
+ ## Model Details
19
+
20
+ - **Architecture**: ViT-L based Transformer (SAM backbone + Cellpose readout)
21
+ - **Parameters**: 304M
22
+ - **Input**: `pixel_values` — float32 tensor `(1, 3, 256, 256)` (one tile)
23
+ - **Output**: `output` — float32 tensor `(1, 3, 256, 256)` — channels are `(dY, dX, cellprob)`
24
+ - **Opset**: 14
25
+
26
+ The model weights are stored as external data (`model.onnx.data`) due to the 2GB protobuf limit.
27
+ Both files must be in the same directory for inference.
28
+
29
+ ## Usage
30
+
31
+ ### Python (onnxruntime)
32
+ ```python
33
+ import onnxruntime as ort
34
+ import numpy as np
35
+
36
+ sess = ort.InferenceSession("model.onnx", providers=["CUDAExecutionProvider"])
37
+ tile = np.zeros((1, 3, 256, 256), dtype=np.float32) # your preprocessed tile
38
+ output = sess.run(None, {"pixel_values": tile})[0] # (1, 3, 256, 256)
39
+ dY, dX, cellprob = output[0, 0], output[0, 1], output[0, 2]
40
+ ```
41
+
42
+ ### Rust (cellpose-rs)
43
+ ```rust
44
+ use cellpose_rs::{CellposeSession, SegmentParams, preprocess};
45
+
46
+ let mut session = CellposeSession::new(Path::new("model.onnx"), false)?;
47
+ let chw = preprocess::build_chw_image(phase, fluo, h, w);
48
+ let masks = session.segment(&chw, h, w, SegmentParams::default())?;
49
+ ```
50
+
51
+ See [cellpose-rs](https://github.com/keejkrej/cellpose-rs) for the full Rust inference library.
52
+
53
+ ## Post-processing
54
+
55
+ The raw output requires Cellpose flow dynamics post-processing:
56
+ 1. Threshold `cellprob > 0` to get foreground
57
+ 2. Scale flows: `dP = dP * foreground / 5.0`
58
+ 3. 200-step Euler integration with bilinear interpolation
59
+ 4. Histogram-based seed detection (max-pool kernel=5, threshold=10)
60
+ 5. Connected-component labelling of seeds
61
+ 6. Assign each foreground pixel to its nearest seed
62
+ 7. Remove masks >40% of image area, fill holes, remove masks <15px
63
+
64
+ ## License
65
+
66
+ The Cellpose **code** is © 2020 Howard Hughes Medical Institute, licensed under the
67
+ [BSD 3-Clause License](https://github.com/MouseLand/cellpose/blob/main/LICENSE).
68
+
69
+ ⚠️ The Cellpose-SAM model is trained on data licensed under **CC-BY-NC**.
70
+ See the [upstream notice](https://github.com/MouseLand/cellpose#readme).
71
+
72
+ ## Citation
73
+
74
+ If you use this model, please cite the Cellpose-SAM paper:
75
+
76
+ > Pachitariu, M., Rariden, M., & Stringer, C. (2025).
77
+ > Cellpose-SAM: superhuman generalization for cellular segmentation.
78
+ > *bioRxiv*. https://doi.org/10.1101/2025.04.28.651001
79
+
80
+ ```bibtex
81
+ @article{pachitariu2025cellposesam,
82
+ title={Cellpose-SAM: superhuman generalization for cellular segmentation},
83
+ author={Pachitariu, Marius and Rariden, Maia and Stringer, Carsen},
84
+ journal={bioRxiv},
85
+ year={2025},
86
+ doi={10.1101/2025.04.28.651001}
87
+ }
88
+ ```
model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73447d51ffe775e72b42d6123cbc7438738f6dbe33ecf2a4ffa60a4fb6f76c05
3
+ size 1583514
model.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae011bfeb8e6291fb3652a08fa9c80d5648c2140813563d79057b82d21fa18a8
3
+ size 1230569472