File size: 3,666 Bytes
ddb305c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9a30a96
397320b
9a30a96
 
 
 
 
 
 
 
ddb305c
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
license: cc-by-4.0
tags: [cellpose, cellpose-sam, segmentation, microscopy, toxoplasma, cross-channel, spacr]
pipeline_tag: image-segmentation
---
# Cross-channel cell from hoechst (Cellpose-SAM)

Fine-tuned from stock `cpsam_v2` (CellposeSAM), 100 epochs, file-mode training.
Built for use with [spaCR](https://github.com/EinarOlafsson/spacr).

## Data
2578 training fields (237957 annotated objects), 451 held-out test fields
(45098 objects); 451 test fields contained objects and were scored.
Split **by well**, so no well appears on both sides. Per-field split and counts: `training/fields.csv`.

## Results (held-out, best epoch 70)

| model | F1 | precision | recall | mAP | AJI | Dice |
|---|---|---|---|---|---|---|
| stock cpsam_v2 | 0.3012 | 0.3086 | 0.2942 | 0.0575 | 0.3506 | 0.5235 |
| **best** | 0.8697 | 0.9437 | 0.8064 | 0.5591 | 0.7991 | 0.8948 |
| final | 0.8667 | 0.9429 | 0.8018 | 0.552 | 0.7929 | 0.8904 |

F1 improves **0.5685** over stock
(2.89x). The mAP ratio is inflated by a near-zero stock
denominator (0.0575) - quote the delta, not the ratio.

## Installation

This model is trained and used with [**spaCR**](https://github.com/EinarOlafsson/spacr), a toolkit for
spatial phenotype analysis of high-content microscopy screens.

```bash
pip install spacr                      # https://pypi.org/project/spacr/
conda install -c conda-forge spacr     # https://anaconda.org/conda-forge/spacr
```

- Source: <https://github.com/EinarOlafsson/spacr>
- PyPI: <https://pypi.org/project/spacr/>
- conda-forge: <https://anaconda.org/conda-forge/spacr>

## Get the weights

```python
from huggingface_hub import hf_hub_download
w = hf_hub_download("einarolafsson/cross-channel-cell-from-hoechst-cpsam", "weights/cell_from_hoechst")
```

## Use in spaCR

spaCR takes a **path** to a custom Cellpose model via the `custom_model` setting, so point it at the
file downloaded above:

```python
from spacr.core import preprocess_generate_masks

settings = {
    "src": "/path/to/your/plate",
    "cell_channel": 0,          # the cell-mask channel this model reads
    "nucleus_channel": 1,
    "custom_model": w,          # path from hf_hub_download above
    "preprocess": True,
    "masks": True,
}
preprocess_generate_masks(settings)
```

One caveat worth knowing: `pathogen_model` is **not** a free-form path. spaCR validates it against a
fixed list (`['toxo_pv_lumen', 'toxo_cyto']`), so a custom model on disk goes through `custom_model`,
not `pathogen_model`. See `spacr/settings.py` and `spacr/core.py`.

## Use with Cellpose directly

```python
from cellpose import models
m = models.CellposeModel(gpu=True, pretrained_model=w)
masks = m.eval(img, normalize=True)[0]
```

Always pass a real path. Cellpose silently substitutes its own default model for an unrecognised
bare name, which would quietly give you the wrong weights.


## Environment

| | |
|---|---|
| cellpose (training) | 4.0.9 |
| cellpose (scoring) | 4.0.9 |
| GPU | NVIDIA GeForce RTX 3090 Ti |
| base weights | cpsam_v2 |

## Contents
- `weights/` - final and best
- `checkpoints/` - epoch snapshots
- `qc/` - per-image and per-IoU metrics, per-tag summaries, `comparison_vs_stock.csv`
- `training/` - `loss_per_epoch.csv` (per-epoch train and validation loss), `metrics.csv`
  (per-checkpoint F1/precision/recall/mAP/AJI/Dice), curves, `fields.csv`, `report.json`

Metrics are at IoU 0.50-0.95 in 0.05 steps; every model is scored against stock `cpsam_v2` on the
identical holdout so "better than stock" is always answerable.

Training data: [einarolafsson/cross-channel-cell-from-hoechst](https://huggingface.co/datasets/einarolafsson/cross-channel-cell-from-hoechst)