joda001 commited on
Commit
9585a5c
·
verified ·
1 Parent(s): 6e10a42

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -3
README.md CHANGED
@@ -1,5 +1,112 @@
1
  ---
2
  license: bsd-3-clause
3
- base_model:
4
- - mouseland/cellpose-sam
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: bsd-3-clause
3
+ library_name: safetensors
4
+ pipeline_tag: image-segmentation
5
+ tags:
6
+ - cellpose
7
+ - cellpose-sam
8
+ - cell-segmentation
9
+ - microscopy
10
+ - bioimage-analysis
11
+ - safetensors
12
+ base_model: mouseland/cellpose-sam
13
+ ---
14
+
15
+ # Cellpose-SAM (cpsam_v2) – safetensors
16
+
17
+ This is the **Cellpose-SAM `cpsam_v2`** model by Pachitariu, Rariden and Stringer
18
+ (MouseLand), converted from the original PyTorch checkpoint to
19
+ [safetensors](https://github.com/huggingface/safetensors).
20
+
21
+ The weights are **unchanged**. They are only stored in another file format. I did not
22
+ retrain or fine-tune anything. The original model is at
23
+ [mouseland/cellpose-sam](https://huggingface.co/mouseland/cellpose-sam).
24
+
25
+ I made this conversion for [EVAnalyzer](https://github.com/evanalyzer/evanalyzer), which runs
26
+ Cellpose-SAM through its own Rust implementation and does not need Python or PyTorch. The
27
+ file is a plain safetensors file, so any other tool that reads safetensors can load it too.
28
+
29
+ ## Files
30
+
31
+ | File | Content |
32
+ |---|---|
33
+ | `cpsam_v2.evanet` | the weights as safetensors, f32, about 1.2 GB |
34
+
35
+ `.evanet` is EVAnalyzer's extension for neural network models. The file itself is a
36
+ standard safetensors file, so you can rename it to `.safetensors` if your tool needs that.
37
+
38
+ ## What changed in the conversion
39
+
40
+ - The tensors keep Cellpose's PyTorch names (`encoder.blocks.0.attn.qkv.weight`, ...) and
41
+ are stored as f32. The `module.` prefix from DataParallel is removed.
42
+ - The relative position tables (`rel_pos_h` / `rel_pos_w`) keep SAM's original sizes
43
+ (27 rows in the windowed blocks, 127 in the global blocks).
44
+ - `W2` is left out. It is a fixed identity matrix (the pixel shuffle of the output). The
45
+ script checks that it is the identity before it removes it.
46
+ - `diam_labels` and `diam_mean` are left out because the network does not use them.
47
+ - `__metadata__` holds the architecture and the source:
48
+ - `evanalyzer_arch`: `cellpose_sam`
49
+ - `arch_version`: `1`
50
+ - `config`: `{"in_channels":3,"tile_size":256,"patch_size":8,"embed_dim":1024,"depth":24,"num_heads":16,"mlp_dim":4096,"neck_dim":256,"out_channels":3}`
51
+ - `source`, `license`, `citation`
52
+
53
+ ## Check against the original
54
+
55
+ The conversion script also runs Cellpose's own `CPSAM` module (f32, CPU) on three fixed
56
+ 256 × 256 test tiles: gray with zero-filled channels, gray copied to all channels, and a
57
+ single channel. EVAnalyzer's test suite compares its output with these reference outputs.
58
+
59
+ ## Use in Python with Cellpose
60
+
61
+ The file loads into Cellpose's `CPSAM`. You only have to add the identity `W2` again:
62
+
63
+ ```python
64
+ import torch
65
+ from safetensors.torch import load_file
66
+ from cellpose.vit import CPSAM
67
+
68
+ state = load_file("cpsam_v2.evanet")
69
+ net = CPSAM()
70
+ w2 = net.state_dict()["W2"]
71
+ state["W2"] = torch.eye(w2.shape[0]).reshape(w2.shape)
72
+ net.load_state_dict(state, strict=False) # diam_labels / diam_mean keep their defaults
73
+ net.eval()
74
+ ```
75
+
76
+ ## Input and output
77
+
78
+ - Input: tiles of 256 × 256 pixels with 3 channels. Normalize each image to about 0..1 with
79
+ Cellpose's `normalize99` (1st and 99th percentile) before you tile it.
80
+ - Output per tile: 3 channels, `dY`, `dX` (the flow field) and the cell probability as a
81
+ logit. To get masks, use Cellpose's flow-following post-processing.
82
+
83
+ ## License
84
+
85
+ The original weights are published under **BSD-3-Clause** (Cellpose, © HHMI). The SAM image
86
+ encoder the model starts from is **Apache-2.0** (© Meta). This conversion keeps these
87
+ licenses. See the original repositories for the full license texts.
88
+
89
+ **Training data:** the Cellpose README says that the Cellpose models are trained on data
90
+ that is licensed under **CC-BY-NC**. Check if this matters for your use, especially for
91
+ commercial use. If you are unsure, ask the Cellpose authors.
92
+
93
+ ## Citation
94
+
95
+ If you use this model, please cite the original work:
96
+
97
+ ```bibtex
98
+ @article{pachitariu2025cellposesam,
99
+ title = {Cellpose-SAM: superhuman generalization for cellular segmentation},
100
+ author = {Pachitariu, Marius and Rariden, Michael and Stringer, Carsen},
101
+ journal = {bioRxiv},
102
+ year = {2025},
103
+ doi = {10.1101/2025.04.28.651001}
104
+ }
105
+ ```
106
+
107
+ ## Credits
108
+
109
+ All credit for the model goes to the Cellpose authors at
110
+ [MouseLand](https://github.com/MouseLand/cellpose) and to Meta for
111
+ [Segment Anything](https://github.com/facebookresearch/segment-anything). This repository
112
+ is not affiliated with or endorsed by them.