Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4b62365
fix(viscy-utils): fall back to TensorBoard logger when wandb is absen…
ieivanov Jun 29, 2026
4a4ac9f
Port shared VisCy package changes from DynaCell v1.1 (#533)
alxndrkalinin Nov 3, 2026
7286fb2
DynaCell v1.1 application (#534)
alxndrkalinin Nov 4, 2026
032c8cc
chore(repo): clear the 99 critical and high Dependabot alerts (#537)
srivarra Nov 5, 2026
d25a6f5
docs(dynaclr): add Infectomics Imaging open-data demo notebook (#544)
mattersoflight Dec 1, 2026
b67a38b
Point VisCy and waveorder links at their Biohub GitHub home (#539)
alxndrkalinin Dec 1, 2026
f85c029
feat(dynacell): add the stain skill for virtual staining inference
alxndrkalinin Dec 2, 2026
9ce6e78
feat(dynacell): add the train-stain skill for single-GPU fits
alxndrkalinin Dec 2, 2026
7cbcc3b
feat(dynacell): add the eval-stain skill for scoring predictions
alxndrkalinin Dec 2, 2026
7ff5cca
docs(dynacell): record strict loading of all released stain checkpoints
alxndrkalinin Dec 2, 2026
a033081
docs(dynacell): correct the FNet3D run-time estimate and diagram labels
alxndrkalinin Dec 2, 2026
56cc708
refactor(dynacell): name the stain skills dynacell-stain-{predict,tra…
alxndrkalinin Dec 2, 2026
ac89765
docs(dynacell): turn the stain skills into guided walkthroughs
alxndrkalinin Dec 2, 2026
94690e5
docs(dynacell): cover every released family in the stain skills
alxndrkalinin Dec 2, 2026
c615a44
docs(dynacell): tie stain-skill claims to what was measured
alxndrkalinin Dec 2, 2026
f0f16ac
docs(dynacell): smoke-test slow stain models on one volume
alxndrkalinin Dec 2, 2026
6f965a7
docs(dynacell): record that 2 ViT patches do not fit a 48 GB GPU
alxndrkalinin Dec 2, 2026
e5087f6
docs(dynacell): train VSCyto3D from the published FCMAE pretrain
alxndrkalinin Dec 2, 2026
fbcb5d3
docs(dynacell): download the VSCyto3D pretrain from dynacell-checkpoints
alxndrkalinin Dec 2, 2026
a8b352b
Merge PR 540 base into staining skills and resolve names for the stac…
edyoshikun Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions applications/dynacell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
| --- | --- | --- |
| [`$dynacell-embed`](skills/dynacell-embed/SKILL.md) | `dynacell embed` | Extract raw cell embeddings |
| [`$dynacell-phenotype`](skills/dynacell-phenotype/SKILL.md) | `dynacell phenotype` | Compare populations with matched controls |
| [`$dynacell-stain`](skills/dynacell-stain/SKILL.md) | `dynacell predict` | Predict fluorescence from phase images |
| [`$dynacell-stain-eval`](skills/dynacell-stain-eval/SKILL.md) | `dynacell evaluate` | Compare predicted and measured fluorescence |
| [`$dynacell-stain-train`](skills/dynacell-stain-train/SKILL.md) | `dynacell fit` | Train or fine-tune a staining model |

**An evaluation framework for dynamic 3D virtual staining of live cells.**

Expand Down
28 changes: 28 additions & 0 deletions applications/dynacell/skills/dynacell-stain-eval/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2023, CZ Biohub SF

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102 changes: 102 additions & 0 deletions applications/dynacell/skills/dynacell-stain-eval/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
name: dynacell-stain-eval
description: Walk a user through scoring virtual-staining predictions against fluorescence ground truth with the DynaCell evaluation suite - pixel metrics (PCC, SSIM, scale-invariant and foreground variants, FSC) and organelle segmentation metrics (Dice, IoU, instance AP for nucleus and membrane) - and through interpreting and comparing the results. Use after dynacell-stain, dynacell-stain-train or any model that writes an HCS OME-Zarr prediction. Needs a client that can run shell commands where the data and an NVIDIA GPU are. Not for running inference (dynacell-stain) or training (dynacell-stain-train).
---

# Evaluate virtual staining: guided

Guide the user from a prediction store to metrics they understand and can
compare. This is an **interactive** skill: ask one question at a time, run the
commands, and interpret the numbers together.

**Requirements.** Commands run in the user's environment on a Linux machine
with an NVIDIA GPU (about 16 GB) that can read both stores. If the client
cannot run commands, give the user the commands and ask for the output; never
claim a run you did not see. Read [local execution](references/setup.md).

Supporting files, relative to this skill folder (over MCP, read them as
`skill://dynacell-stain-eval/<path>`):

- [references/setup.md](references/setup.md): install, runtime commit, GPU sizing, MCP handling
- [references/metrics.md](references/metrics.md): commands per organelle, required keys, metrics, outputs, reference values, comparing models

---

## Stage 1: What will be measured

Explain briefly:

- **Pixel metrics** compare prediction and fluorescence voxel by voxel (PCC,
SSIM and variants).
- **Mask metrics** segment both and compare the organelle masks (Dice, IoU);
for nucleus and membrane also per-object accuracy (instance AP).
- Not available in this version: feature and realism metrics (CellProfiler,
DINOv3, DynaCLR and CellDINO embedding distances, KID/FID). They need
reference data and checkpoints that are not public yet.
- The ground truth must be real fluorescence of the same cells, never the
model's input or another prediction.

**Ask:** "Which prediction store and which fluorescence store, and which
organelle?"

## Stage 2: Check that the stores line up

Inspect both stores (channels, positions, timepoints, shape, scale), for
example with the snippet in [metrics](references/metrics.md#checking-the-stores).
Walk through the result:

1. Positions are matched by name; both stores need the same positions.
2. Each position needs the same number of timepoints and the same ZYX shape.
A prediction on a FOV subset can be scored with `limit_positions` (first N
positions); a timepoint subset cannot be scored against the full GT.
3. Voxel size: read it from the stores, or ask. Public hiPSC archives store an
identity scale; hiPSC is `[0.290, 0.108, 0.108]` µm, A549
`[0.174, 0.1494, 0.1494]` µm.
4. For membrane, find a store with GT nuclei and the same position names.

## Stage 3: Smoke test

Build the command for the organelle from [commands](references/metrics.md#commands),
add `limit_positions=1`, and run it. Confirm `pixel_metrics.csv` and
`mask_metrics.csv` appear in `save.save_dir`, and show the user the first rows.
The first nucleus or membrane run downloads Cellpose-DINO weights (about 1.2 GB).

## Stage 4: Full evaluation

Estimate the time (about 1-2 min per position of 10 timepoints on an A40), agree
on the scope, remove `limit_positions`, use a new `save.save_dir`, and run.

## Stage 5: Interpret together

Summarize mean and spread of the headline metrics with the number of
position x timepoint volumes, and explain them:

- PCC and SSIM near 1 mean close agreement; compare with the
[reference values](references/metrics.md#reference-values) of the released
models on the public test data to calibrate expectations.
- If pixel metrics are high but Dice is low, the intensities agree but object
boundaries do not; look at `segmentation_results.zarr` together.
- `FG_*` metrics ignore background agreement; trust them over whole-image
metrics when most of the volume is empty.
- Metrics on a subset are a subset; MicroMS3IM values from subsets are not
comparable to full runs.

**Ask** whether the result answers their question, or whether they want to
compare models or check specific positions.

## Stage 6: Compare models (optional)

Evaluate each model on the same GT and positions, one `save.save_dir` each,
then run `dynacell report` ([comparing models](references/metrics.md#comparing-models))
and walk through the table.

## Rules

- Always pass `compute_feature_metrics=false`.
- Do not use `leaf=`, `target=` or `predict_set=` config groups or
`benchmark.dataset_ref`; they resolve Biohub-internal dataset manifests.
- Always pass `pixel_metrics.spacing`.
- Never evaluate a model on data it was trained on. For DynaCell checkpoints use
only `test/` archives.
- Re-runs reuse valid results in `save.save_dir`; add
`force_recompute.final_metrics=true` to recompute.
54 changes: 54 additions & 0 deletions applications/dynacell/skills/dynacell-stain-eval/evals/evals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"skill_name": "dynacell-stain-eval",
"evals": [
{
"id": 1,
"prompt": "Evaluate my FNet3D ER predictions in pred.zarr (channel Structure_prediction) against the public A549 SEC61B mock test archive.",
"expected_output": "Runs dynacell evaluate with target_name er, the channel names, A549 spacing, compute_feature_metrics=false and a save directory, smoke-tests with limit_positions=1, and reports PCC, SSIM and Dice with the number of volumes.",
"files": [],
"expectations": [
"The command sets target_name=er, io.gt_channel_name=Structure and io.pred_channel_name=Structure_prediction.",
"The command passes pixel_metrics.spacing=[0.174,0.1494,0.1494] and compute_feature_metrics=false.",
"The agent does not use leaf=, target= or predict_set= groups.",
"The agent smoke-tests with limit_positions before the full run.",
"The agent reports means with the count of FOV x timepoint volumes and the output directory."
]
},
{
"id": 2,
"prompt": "Score virtual membrane predictions for the A549 ZIKV test set and give me instance segmentation accuracy too.",
"expected_output": "Uses target_name membrane with segmentation.backend=cpdino, compute_instance_ap=true, the CAAX_ZIKV GT and the H2B_ZIKV archive as io.nuclei_gt_path with nuclei_channel_name Nuclei.",
"files": [],
"expectations": [
"The command sets segmentation.backend=cpdino and compute_instance_ap=true.",
"The command sets io.nuclei_gt_path to the H2B_ZIKV archive and segmentation.nuclei_channel_name=Nuclei.",
"The GT is CAAX_ZIKV.ozx with io.gt_channel_name=Membrane.",
"The agent reports mAP alongside Dice and PCC."
]
},
{
"id": 3,
"prompt": "Compute KID, FID and CellProfiler feature distances for my predictions versus the DynaCell ground truth.",
"expected_output": "Explains that the feature tier (CP, DINOv3, DynaCLR, CellDINO, KID/FID) is not available in this version because it needs unpublished reference data and checkpoints, and offers pixel and mask metrics instead.",
"files": [],
"expectations": [
"The agent says feature and realism metrics are not available in this version.",
"The agent does not run with compute_feature_metrics=true or invent reference paths.",
"The agent does not download or request CellDINO weights to work around it.",
"The agent offers the pixel and mask evaluation."
]
},
{
"id": 4,
"prompt": "I predicted 3 of the 12 FOVs and only timepoints 0-4 of the A549 SEC61B mock test archive. Evaluate them.",
"expected_output": "Explains that positions are matched by name and timepoints must match per position, so a FOV subset can be scored with limit_positions if the predicted FOVs are the first ones, but a timepoint subset cannot be scored against the full GT; suggests predicting all timepoints of those FOVs.",
"files": [],
"expectations": [
"The agent states that each position needs the same number of timepoints in prediction and GT.",
"The agent does not report metrics for the timepoint subset as if they were valid.",
"The agent explains limit_positions for FOV subsets.",
"The agent suggests re-predicting all timepoints of the chosen FOVs."
]
}
]
}
176 changes: 176 additions & 0 deletions applications/dynacell/skills/dynacell-stain-eval/references/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Evaluation commands, metrics and outputs

`dynacell evaluate` is a Hydra command: every setting is a `key=value`
override. Quote any override that contains brackets.

## Required keys

| Key | Meaning |
| --- | --- |
| `target_name` | `nucleus`, `membrane`, `er` or `mitochondria`; selects the segmentation workflow |
| `io.pred_path` | prediction store (HCS OME-Zarr, `.zarr` or `.ozx`) |
| `io.pred_channel_name` | channel in the prediction store, e.g. `Structure_prediction` |
| `io.gt_path` | GT store with the same positions, timepoints and ZYX shape |
| `io.gt_channel_name` | GT channel: `Nuclei`, `Membrane` or `Structure` in DynaCell archives |
| `pixel_metrics.spacing` | voxel size `[z, y, x]` in µm |
| `save.save_dir` | output directory |
| `compute_feature_metrics=false` | always; see the rule in `SKILL.md` |

Useful optional keys: `limit_positions=N` (first N positions only),
`force_recompute.final_metrics=true` (ignore saved results),
`compute_microssim=false` (skip MicroMS3IM to save time).

## Checking the stores

```python
from iohub import open_ome_zarr

for path in ["predictions/fnet3d_er.zarr", "data/SEC61B_mock.ozx"]:
with open_ome_zarr(path, mode="r") as plate:
positions = {name: pos["0"].shape for name, pos in plate.positions()}
first = next(iter(positions))
print(path, plate.channel_names, len(positions), "positions;",
first, positions[first], "scale", plate[first].scale)
```

Compare the position names, the T and ZYX parts of the shapes, and the channel
names between the two lines.

## Commands

### ER or mitochondria

Segmented with classical Allen Cell Structure Segmenter workflows (no model
weights). Verified on A549 ER: PCC and Dice matched the DynaCell internal
evaluation of the same predictions to within 2e-5.

```bash
dynacell evaluate \
target_name=er \
io.pred_path=predictions/fnet3d_er.zarr \
io.pred_channel_name=Structure_prediction \
io.gt_path=data/SEC61B_mock.ozx \
io.gt_channel_name=Structure \
'pixel_metrics.spacing=[0.174,0.1494,0.1494]' \
compute_feature_metrics=false \
save.save_dir=eval/fnet3d_er_mock
```

For mitochondria set `target_name=mitochondria` and use the TOMM20 archive
(`Structure` channel). The mitochondria path was not run for this skill.

### Membrane

Whole-cell segmentation with Cellpose-DINO (`cpdino`) needs the GT nuclei to
carve each cell, and `cpdino` requires instance AP to be on. Verified on A549
membrane: PCC matched the internal evaluation to 2e-5, Dice to 0.004 and mAP to
0.003 (Cellpose-DINO masks vary slightly between GPU types).

```bash
dynacell evaluate \
target_name=membrane \
io.pred_path=predictions/fnet3d_membrane.zarr \
io.pred_channel_name=Membrane_prediction \
io.gt_path=data/CAAX_mock.ozx \
io.gt_channel_name=Membrane \
io.nuclei_gt_path=data/H2B_mock.ozx \
segmentation.nuclei_channel_name=Nuclei \
segmentation.backend=cpdino \
compute_instance_ap=true \
'pixel_metrics.spacing=[0.174,0.1494,0.1494]' \
compute_feature_metrics=false \
save.save_dir=eval/fnet3d_membrane_mock
```

- A549 keeps membrane GT (`CAAX_<condition>.ozx`) and nuclei GT
(`H2B_<condition>.ozx`) in separate archives with the same FOV names.
- hiPSC keeps both in `cell.ozx`: omit `io.nuclei_gt_path` (it defaults to the
GT store) and keep `segmentation.nuclei_channel_name=Nuclei`.
- For the user's own data, `io.nuclei_gt_path` points at any store with a
nuclear fluorescence channel and the same position names.

### Nucleus

```bash
dynacell evaluate \
target_name=nucleus \
io.pred_path=predictions/fnet3d_nucleus.zarr \
io.pred_channel_name=Nuclei_prediction \
io.gt_path=data/H2B_mock.ozx \
io.gt_channel_name=Nuclei \
segmentation.backend=cpdino \
compute_instance_ap=true \
'pixel_metrics.spacing=[0.174,0.1494,0.1494]' \
compute_feature_metrics=false \
save.save_dir=eval/fnet3d_nucleus_mock
```

The nucleus path uses the same backend as membrane but was not run for this
skill. Without `segmentation.backend=cpdino` the default nucleus and membrane
segmenter downloads Allen Cell model weights through `quilt3`; that route was
not verified, so prefer `cpdino`.

Cellpose-DINO weights (about 1.2 GB) download anonymously from Hugging Face
(`mouseland/cellpose-sam`) on first use into `~/.cellpose/models`; set
`CELLPOSE_LOCAL_MODELS_PATH` to put them elsewhere.

## Metrics

Pixel metrics (`pixel_metrics.csv`, one row per position x timepoint):

- `PCC`: Pearson correlation of prediction and GT voxels.
- `SSIM`, `NRMSE`, `PSNR`: computed after min-max scaling both volumes.
- `SI_*`: the same metrics after a least-squares scale-and-offset fit of the
prediction to the GT; insensitive to global intensity scaling.
- `FG_*`: weighted by the GT foreground (interior) mask, so background
agreement does not inflate them.
- `Spectral_PCC`, XY and Z Fourier shell correlation resolution, `MicroMS3IM`.

Mask metrics (`mask_metrics.csv`): `Dice`, `IoU`, `Precision`, `Recall` and
`Accuracy` between segmentations of the prediction and of the GT. With
`compute_instance_ap=true`: average precision at IoU 0.50 to 0.95 (`AP_0.50`
... `AP_0.95`), `mAP`, `instance_dice`, and object counts `n_gt` / `n_pred`.

## Reference values

Mean PCC of released A549-trained checkpoints on the public A549 mock test
archives, as measured for this skill (all 12 positions x 10 timepoints unless
noted); the DynaCell internal evaluation agrees:

| Organelle | FNet3D | VSCyto3D | CELL-Diff (fast sampler) |
| --- | --- | --- | --- |
| ER (`SEC61B_mock`) | 0.726 | 0.731 | 0.705 (1 position) |
| Membrane (`CAAX_mock`) | 0.738 (2 positions) | | |

Evaluating a released checkpoint on its public test archive should reproduce
these values to about 0.001 for deterministic models. A large gap points to a
setup problem (wrong channel, normalization or checkpoint), not to the model.

## Outputs in `save.save_dir`

- `pixel_metrics.csv` / `.npy`, `mask_metrics.csv` / `.npy`
- `pixel_metrics/`, `mask_metrics/`: per-metric plots
- `segmentation_results.zarr`: `prediction_seg` and `target_seg` masks
- `metrics_provenance.json`: settings and software versions; keep it with the numbers
- `eval_timing.csv`

The working directory also receives `pipeline.log`.

## Comparing models

Evaluate each model on the same GT and positions, one `save.save_dir` each,
then:

```bash
dynacell report \
+results_dirs.FNet3D=eval/fnet3d_er_mock \
+results_dirs.VSCyto3D=eval/vscyto3d_er_mock \
output_dir=eval/report_er_mock \
figure_format=png
```

The `+` prefix is required: `results_dirs` starts empty. The command prints a
mean +/- standard deviation table and writes `comparison_table.tex` and
`comparison_barplot.<figure_format>` (default `pdf`) for the pixel (`PCC`,
`SSIM`, `NRMSE`, `PSNR`) and mask (`Dice`, `IoU`) metrics. Bold marks the best
model per column.
Loading