spacr.qt.screens.train_cellpose¶
Combined interface for fine-tuning and applying Cellpose models.
The workbench embeds the train_cellpose and cellpose_masks workflows
as Train and Apply tabs, each backed by its own
AppScreen. The Train tab reads
src and mask_src (default <src>/masks) and writes model checkpoints
beneath <src>/models. The Apply tab reads <src>/*.tif from its
independent source directory and writes masks to <src>/masks.
When the active tab changes, settings named by the cellpose_masks
propagation map in spacr.qt.preview_registry are copied to the
destination tab when that tab exposes the corresponding setting. src and
model_name are not copied. On entry to Apply, the workbench searches
<train-src>/models/cellpose_model/models for checkpoints whose names begin
with the Train tab’s model_name. It prefers completed checkpoints over
periodic _epoch_ checkpoints and selects the most recently modified
candidate from the preferred group. If found, that path is assigned to
custom_model, which
spacr.spacr_cellpose.identify_masks_finetune() resolves before
model_name; otherwise, Apply retains its current model selection.
Each tab retains its own settings model, console, Run action, drop handling, and any registered preview. Search, recipe, and preview integrations are installed directly because embedded tabs do not become the current page in the main-window stack.
The combined screen changes only GUI registration. The train_cellpose and
cellpose_masks pipeline keys, command-line entry points, and settings-file
formats remain available.
Classes¶
Train and Apply as two tabs of one module page. |
Functions¶
|
Screen factory for the registry. |
|
The knobs copied from one tab to the other when the tab changes. |
Module Contents¶
- class spacr.qt.screens.train_cellpose.CellposeWorkbenchScreen(parent: PySide6.QtWidgets.QWidget | None = None)[source]¶
Bases:
PySide6.QtWidgets.QWidgetTrain and Apply as two tabs of one module page.
- Variables:
error_explain_requested – re-emitted from whichever tab raised, with
(traceback, app_key)— the app key is the TAB’s, so the AI console is asked about the module that actually failed.remote_submit_requested – re-emitted the same way, so submitting a run to Distributed Jobs from either tab carries that tab’s key and that tab’s settings.
- Parameters:
parent – parent widget.
Build the Cellpose workbench.
The registry key is fixed rather than following the open tab: the window keys its screen table and its navigation by it, and a key that moved would make the page answer to one it is not filed under.
- Parameters:
parent – parent widget, or
None.
- active_screen() spacr.qt.screens.app_screen.AppScreen[source]¶
The module page the user is looking at.
- apply_seed(seed: Dict) int[source]¶
Take a seed handed over by another screen. See
apply_settings_dict(), which decides where it lands.- Parameters:
seed – settings name to value, passed unchanged to
apply_settings_dict().
- apply_settings_dict(settings: Dict) int[source]¶
Push
settingsinto whichever tab the dict is for.A settings CSV, a restored session or a recipe belongs to one of the two modules, and applying it to both would write a training folder into the Apply tab’s path field — the one thing the two-field split exists to prevent. The tab is chosen by which one owns more of the keys the OTHER one does not have, so
n_epochspicks Train andflow_thresholdpicks Apply; a dict that distinguishes neither goes to the tab already on screen. The chosen tab is raised, so the settings are visible where they landed.- Parameters:
settings – key/value pairs to apply.
- Returns:
how many keys the chosen tab actually took.
- carry(source: spacr.qt.screens.app_screen.AppScreen, target: spacr.qt.screens.app_screen.AppScreen) Dict[source]¶
Copy the shared knobs from
sourceintotarget.Only the keys
carried_setting_keys()names, and only thosetargetactually has a widget for — the two forms overlap partially, and a key the target does not offer would otherwise be written into its hidden values where nobody can see or change it. Entering the Apply tab additionally picks up the trained checkpoint.- Parameters:
source – the tab being left.
target – the tab being opened.
- Returns:
what was written into
target.
- carry_trained_model() str[source]¶
Point the Apply tab at the checkpoint the Train tab produced.
Does nothing until a training run has actually written one: a
custom_modelnaming a file that is not there stopsspacr.spacr_cellpose.identify_masks_finetune()before it segments anything, which would break “run cpsam over this folder” for everyone who has never trained a model.- Returns:
the checkpoint path that was set, or
"".
- closeEvent(event)[source]¶
Close both module pages before their owning workbench is destroyed.
- Parameters:
event – Qt close event; ignored when a page is finishing a write.
- screen_for(app_key: str) spacr.qt.screens.app_screen.AppScreen | None[source]¶
The tab that runs
app_key, orNone.- Parameters:
app_key – the app key to find, compared as a string with each tab’s
app_key.
- trained_checkpoint() str[source]¶
The newest checkpoint the Train tab’s settings would have written.
Found by looking, not by rebuilding the file name: the training module stamps the architecture and epoch count into what it saves, and a second copy of that formula here would go stale the first time it changed. Everything under the training output folder whose name starts with the model name counts; a finished run’s save is preferred over the periodic ones it made on the way, and among equals the most recently written wins.
- Returns:
an absolute path, or
""when there is nothing to find.
- property apply_screen: spacr.qt.screens.app_screen.AppScreen[source]¶
The Apply tab’s module page.
- property train_screen: spacr.qt.screens.app_screen.AppScreen[source]¶
The Train tab’s module page.
- spacr.qt.screens.train_cellpose.build_screen(app_key: str = TRAIN_KEY, host=None) CellposeWorkbenchScreen[source]¶
Screen factory for the registry.
Takes
app_keyandhostbecause that is the contractspacr.qt.app._call_screen_factoryoffers; the key is fixed (this screen serves one row) and the host is used only to make the same two connections the window makes on a generic module page.
- spacr.qt.screens.train_cellpose.carried_setting_keys() Tuple[str, ...][source]¶
The knobs copied from one tab to the other when the tab changes.
Read from the propagation map
spacr.qt.preview_registrydeclares forcellpose_masks— the map already answers “which settings is a Cellpose run judged by”, and a second copy of that list here would be one that could disagree with it.model_nameis excluded: it is the one shared name whose MEANING differs between the two halves, and it crosses as a checkpoint path instead (seeCellposeWorkbenchScreen.trained_checkpoint()).srcis not in the map at all, which is what keeps the two path fields independent.
Nested helpers¶
- CellposeWorkbenchScreen._virtual_stain.work()¶
Train, predict and score off the GUI thread.
spacr/qt/screens/train_cellpose.py:370
- _VirtualStainApply.apply.work()¶
Predict off the GUI thread.
spacr/qt/screens/train_cellpose.py:208