Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 11 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,14 @@ src/morphobricks_preprocessing/
channel_by_number (a channel number only when every image has the same channel
IDs at the same C positions, translated once to the ID; #440);
segmentation_cellpose_model.py choose_model (a built-in name or an existing file,
before loading), load_model (the weights file and device verified after loading, no
download without allow_download, SHA-256 recorded, DINOv3 at a pinned commit);
before loading), load_model (the weights file and device verified after loading,
SHA-256 recorded, DINOv3 installed at a pinned commit on a cpdino model's first
load: ensure_dinov3); segmentation_cellpose_weights.py fetch_weights: the chosen
built-in model's file only, from a pinned Hugging Face revision, checked against
its pinned SHA-256 (a cached copy too), a failed download a refusal (owner,
#574: choosing the model and loading it is the consent; no tick);
segmentation_cellpose_eval.py eval_arguments, inference_parameters (what
model.eval is given and what the batch records);
notebook_cellpose.py CellposeWorkflow, ChannelPicker, CellStop: the widgets behind
notebooks/MorphoBricks_Cellpose.ipynb
notebook_stop.py CellStop (one line, no traceback), defined once: cells 2-8
Expand All @@ -317,8 +323,9 @@ src/morphobricks_preprocessing/
notebook_cellpose_install.py what pip does now, then what it installed;
notebook_open_progress.py opening: the wait of opening a run (#574);
notebook_mask_register.py register_step(app, segmentation): cell 5, a
declaration to tick per mask type, then the app's own check, Masks answer,
save, run and Describe the masks
question per mask type (objects or binary, none chosen; objects registered),
then the app's own check, Masks answer, save, run and Describe the masks,
each step shown by notebook_register_progress.py RegisterWait (#574)
notebook_cellpose_preview.py MaskResult, preview_figures: the example result as
ZeroCostDL4Mic draws it (cellpose.plot.show_segmentation), one result per mask
notebook_cellpose_channels.py ChannelPicker, MaskTarget: the output's masks (Both:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

28 changes: 21 additions & 7 deletions docs/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -1399,20 +1399,34 @@ Cellpose's own `model.device` is not evidence (it only repeats the device it was
nothing beyond the network's tensors is verified. The device is the placement of the network's tensors; Cellpose's own post-processing is not
covered by it: Cellpose may move the flow-threshold quality step to the CPU when GPU memory is
short, and always computes the masks from the flows on the CPU on `mps`; that is Cellpose's
behaviour, **not refused**, and the batch records it as a note. Uncached weights are downloaded only on an explicit request; more than
behaviour, **not refused**, and the batch records it as a note. Built-in weights are never
downloaded by Cellpose: choosing a built-in model and loading it is the consent to download that
model's file (owner, #574), which `segmentation_cellpose_weights` fetches from
`mouseland/cellpose-sam` at a pinned commit (`WEIGHTS_REVISION`) and accepts only with its
pinned size and SHA-256 (`PINNED_WEIGHTS`); a copy already in Cellpose's model folder must match
too, else it is refused and left as it is; the file's identity (device, inode, size, modification
time) taken when it is hashed must be unchanged right before and after Cellpose loads it, else
the load is refused. A failed or blocked download is a refusal naming the
model and the URL (a local write error names the folder instead); nothing partial is kept and no other model is used. Cellpose is then given
the file's absolute path. While `model.eval` runs, torch's `UserWarning` starting "Sparse
invariant checks are implicitly disabled" from the `torch` or `cellpose` modules is filtered
(`warnings.catch_warnings`, never a global filter); it does not affect results. More than
three channels are refused (Cellpose reads the first three by position); a blank diameter is
the model's native scale, never an estimate and never 0, and a diameter that gives fewer than one
flow iteration (`int(200 / rescale)` is 0) is refused, never raised to 1. The batch's `model` holds the model
name, the weights file name (or the custom file's path) and its SHA-256, and its `parameters`
every effective setting (diameter in pixels or null with its meaning, thresholds, the **full**
normalisation dictionary given to Cellpose (its defaults read from its module at call time, with
the user's values applied) and the flow iterations `niter` (`int(200 / rescale)`, passed
explicitly), batch and tile size, `channel_axis` 0, device type, versions, `weights_downloaded`
and `weights_source` (the Hugging Face URL Cellpose uses; null for a model file), the device
`notes` and, for a DINOv3 model, the DINOv3 commit). The batch ID is the record's
`new_batch_id()`. The DINOv3 package is installed with `--no-deps` at a pinned commit, the head
of its default branch on 22 November 2026, which is **not verified against `cpdino`**; Cellpose
imports it only when first imported, so the runtime is restarted after installing it.
explicitly), batch and tile size, `channel_axis` 0, device type, versions, `weights_downloaded`,
`weights_source` (the pinned URL, `.../resolve/<revision>/<name>`), `weights_repository` and
`weights_revision` (all three null for a model file), the device `notes` and, for a DINOv3
model, `dinov3_commit`, `dinov3_source` and `dinov3_installed`). The batch ID is the record's
`new_batch_id()`. The DINOv3 package (the code of the `cpdino` networks) is installed on the
first load of a `cpdino` model when none is installed, with `--no-deps` at a pinned commit, the
head of its default branch on 22 November 2026, which is **not verified against `cpdino`**; a
DINOv3 of another commit is refused, not replaced. Cellpose imports it only when first imported
(`cellpose.vit`), so a DINOv3 installed after that needs a restart, and the load says so.
Two-dimensional images only. **A mask the batch publishes is never left without its record
entry**: each mask's SHA-256 and the record write (the batch so far, the same batch ID growing)
happen in `write_mask`'s `on_published`, **under the type's write lock**, before the next image
Expand Down
16 changes: 16 additions & 0 deletions docs/plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1715,3 +1715,19 @@ Raised during review; to be decided before the milestones that need them:
work records; mask headers and projection markers are read as always; *Start fresh*
writes and deletes nothing; a finished run is one `RunInputs.open` opens (review of #547)
(`notebook_restore`, contract §9.2).
86. Does the Cellpose step need the user's tick to download a model's weights, and to install
DINOv3? *Decided (owner, 26 November 2026, v0.9.1, #574):* no. Choosing the model, then
pressing **Preview** or **Segment** (or **Load the model** in the Cellpose notebook), is the
consent to download that model's weights; the "Allow the weights download from Hugging
Face" and "Install DINOv3 now" ticks are removed. Only the chosen model's file is
downloaded, on first use, with a visible "Downloading <model> weights…" line; the record
names the weights exactly; another model is never used instead and a failed download is a
refusal. *Encoding choices of this brick:* the file is downloaded from
`mouseland/cellpose-sam` at a pinned commit (`WEIGHTS_REVISION`, not Cellpose's moving
`main`) and kept only with its pinned size and SHA-256 (`PINNED_WEIGHTS`, the hashes Hugging
Face lists at that commit); a copy already on disk must match too, else it is refused and
left in place; the record adds `weights_repository` and `weights_revision` beside
`weights_source`, `weights_downloaded` and the model's `sha256`. DINOv3 (the code of the
`cpdino` networks, no weights of its own) is installed at its pinned commit only when none
is installed; a DINOv3 of another commit is refused, not replaced
(`segmentation_cellpose_weights`, `segmentation_cellpose_model.ensure_dinov3`).
13 changes: 8 additions & 5 deletions docs/testing/cellpose-stepper-human-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ note anything that looks wrong next to it.
- [ ] There is no **Load the model** button. Each setting (diameter, flow threshold, cell
probability threshold, batch size) has a one-line help beside it saying which way to move
it.
- [ ] Leave the device on `cuda`. If the model's weights are not on this runtime yet, press
**Preview** without the download tick: it refuses and says to allow the download.
- [ ] Tick **Allow the weights download** and press **Preview**: the download shows as **one**
progress bar (no stream of log lines), then a green *Model ... loaded on cuda* card and the
preview figures for the image in the dropdown.
- [ ] There is no **Allow the weights download** tick and no **Install DINOv3 now** tick.
- [ ] Leave the device on `cuda`. With the model's weights not on this runtime yet, press
**Preview**: a line **Downloading cpsam_v2 weights…** shows the megabytes received of the
total (no stream of log lines), then *done in m:ss*, then a green *Model ... loaded on
cuda* card (it names the repository and revision) and the preview figures for the image
in the dropdown.
- [ ] Press **Preview** again after a runtime restart: nothing downloads; the card says the
weights on this computer match the pinned file.
- [ ] Choose another image and press **Preview**: no loading card appears this time (the model is
reused); the preview is of the new image.
- [ ] Change the diameter and press **Preview**: still no reload; the new diameter is used.
Expand Down
55 changes: 43 additions & 12 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,29 @@ banner then says "commit unknown" and that the override is on). Then:
channels, so more are refused.
- **Model.** `cpsam_v2` (default), `cpsam`, `cpdino`, `cpdino-vitb` or a model file of your
own. A name or file that does not exist is refused: Cellpose itself would silently use
`cpsam_v2`. The weights of a built-in model are downloaded from Hugging Face on first use,
only if you tick the download box. `cpdino` models also need DINOv3, installed at a pinned
commit (the head of its default branch on 22 November 2026, not verified against `cpdino`; installed without its dependencies) only if you tick its box. Restart the runtime after installing it, then run the cells again.
`cpsam_v2`.
- **Weights download (owner, #574).** Choosing a built-in model and pressing **Preview** or
**Segment** (or **Load the model** in the Cellpose notebook) is your consent to download that
model's weights; there is no box to tick. The first time, only that model's file is
downloaded, from Hugging Face (`mouseland/cellpose-sam` at the pinned revision
`7c61431b5fbb`, never the moving `main` branch), with a line such as **Downloading cpsam_v2
weights…** (megabytes, a bar, the time). The file must have its pinned size and SHA-256
before it is used; a copy already on this computer (in Cellpose's model folder) is checked
too, and one that differs is refused, not used and not replaced: delete it and press the
button again. A failed or blocked download stops with a message naming the model and the
URL; nothing partial is kept, and no other model is ever used instead.
- **DINOv3 (`cpdino` models).** DINOv3 is the code of the `cpdino` networks (their weights are
all in the Cellpose file). When no DINOv3 is installed, the first load of a `cpdino` model
installs it, without its dependencies, at a pinned commit (the head of its default branch on
22 November 2026, not verified against `cpdino`). A DINOv3 of another commit is not
replaced: the load is refused with the command to run. In the combined notebook, cell 4's
**Install Cellpose** installs the pinned DINOv3 code just before Cellpose when none is
installed (v0.9.1), so a `cpdino` model works without a restart whichever model you load
first. A restart is asked for only when it is really needed: DINOv3 was installed after
Cellpose had been loaded in this runtime (for example a `cpsam` model loaded first in the
Cellpose notebook); then restart the runtime and run the cells again; nothing is downloaded
again. A DINOv3 that cannot be imported at all is refused with its import error instead,
since a restart would not fix it.
- **Device.** The model form says, before anything loads, whether a GPU was found and which.
You choose `cuda`, `mps` or `cpu`. A GPU that is not available is refused, never
replaced by the CPU, and after loading every parameter and buffer of the network must be on
Expand All @@ -310,9 +330,13 @@ banner then says "commit unknown" and that the override is on). Then:
decrease if merged), the flow threshold (0.4; increase to keep more objects, decrease if they
are badly shaped), the cell probability threshold (0; decrease to find more and larger
objects, increase for fewer) and the batch size (8; lower it if the GPU runs out of memory).
- **Download display.** While a model loads, a weights download shows as one progress bar and
Cellpose's log lines are not printed; its warnings are shown in one card. What is loaded is
unchanged: the same file, no download without the tick, no substitution, no device fallback.
- **Download display.** While a model loads, a weights download shows as one line with its
progress, then how long it took; Cellpose's log lines are not printed and its warnings are
shown in one card. Cellpose never downloads anything itself: it is given the checked file.
- **One torch warning is hidden.** While Cellpose runs, torch's *UserWarning: Sparse invariant
checks are implicitly disabled…* (from Cellpose's `dynamics.py`) is not shown. Only that
warning, from torch or Cellpose, only during the call; it is about validating sparse tensors
and does not change any result. Every other warning is shown.
- **Diameter** is in pixels. Blank means the model's own native scale (Cellpose 4.2.1.1 does
not estimate a diameter); 0 is refused.
- **Normalisation** is always Cellpose's own, per image (each channel to its 1st to 99th
Expand All @@ -323,7 +347,7 @@ banner then says "commit unknown" and that the override is on). Then:
- **Result.** One mask per image at `<masks>/<type>/<the image's folders>/<image>.tif`
(2D, `int32`, 0 is background, the image's width and height), never over an existing mask
unless you tick overwrite, and `<masks>/<type>/segmentation_record.json` with the model's
file name and SHA-256, every setting (the full normalisation and the flow iterations included), whether the weights were downloaded now and from where, the channels, the device and each image as written,
file name and SHA-256, every setting (the full normalisation and the flow iterations included), where the weights come from (`weights_repository`, `weights_revision`, `weights_source`) and whether they were downloaded now (`weights_downloaded`), for a `cpdino` model the DINOv3 commit and source and whether it was installed now, the channels, the device and each image as written,
skipped or failed. The final table lists every image, with the error of a failed one.
- **The masks folder is checked when the run is opened.** **Open the run** refuses a masks
folder that is the run's output folder or the experiment folder, or inside or around either,
Expand Down Expand Up @@ -365,11 +389,18 @@ run the experiment in the app of cell 3. Then:
reuses it) and **Segment** (it reuses the loaded model, and says in one line exactly which
model and settings it will use, in amber with what differs when the last Preview used
others). One line after the batch points to cell 5.
- **5. Register the masks** shows, for each mask type cell 4 wrote, the declaration it would
add (`[masks.Cells]` with `source_type = "Cells"` and `representation = "instances"`). Tick
each one and press **Register the masks**: the app of cell 3 then checks the folders again
with the masks folder, answers the mask on **Masks**, saves the description, runs again
(the histograms of unchanged images are reused) and describes the masks. Masks written into
- **5. Register the masks** asks, for each mask type cell 4 wrote, what the mask is, with no
answer chosen: *Each object has its own number (label image: every cell/nucleus is a
separate object)* or *Foreground / background only (binary mask)*. They are measured
differently, and the notebook never guesses which one a file is. Cellpose gives each object
its own number, so only the first is registered (the second is refused, saying why); the
declaration it adds (`[masks.Cells]` with `source_type = "Cells"` and `representation =
"instances"`) is shown folded under the question. Answer each one and press **Register the
masks**: the app of cell 3 then checks the folders again with the masks folder, answers the
mask on **Masks**, saves the description, runs again (the histograms of unchanged images are
reused) and describes the masks. Each step is shown under the button as it goes ("Step 4 of
5 · Running again…", its elapsed time, and the step's own line: the image read now, "n of
N"), then how long it took. Masks written into
the masks folder the run already used are fine. If its folder check asks you to confirm the
axes again, do it in cell 3 (step **Axes**) and press the button again (or run cell 5
again). It refuses, changing nothing, a mask type that collides with a mask already declared,
Expand Down
Loading
Loading