cellmap_flow.dashboard.routes.finetune.view_labels
Labelling the box on screen in one click: from the model’s prediction, or all background.
Two buttons beside “Mark This View as Good”, over the same box (one model
output patch centred where the viewer looks, good_regions.view_box_nm,
or box_voxels annotation voxels when the request gives them):
POST
/api/finetune/view-labels/seed: the model’s prediction there, segmented into objects, each written with an id of its own (2 and up), and background 1. The user then cleans it up with the brush; it is far quicker than painting a whole object from nothing. How it is segmented is the request’smethod, one of thepost.segmentsegmenters that fits what the model outputs (SEED_METHODS);seed_sourcessays which fit each running model.POST
/api/finetune/view-labels/background: every unannotated voxel 1, for a region the model fills with false positives.
Both fill only unannotated voxels (session.fill): a voxel the user
painted is a decision, a seed is a guess. The write goes to MinIO, which
neuroglancer reads, and the changed chunks are pulled to disk at once.
Neuroglancer keeps the chunks it has already read, so the page reloads the
viewer afterwards to show the new labels.
A box over LARGE_BOX_VOXELS voxels is only labelled when the request says
confirm: true; without it the answer is a 409 with
needs_confirmation, for the page to ask first.
Attributes
Functions
|
|
|
The seed methods that fit a model's output, the best fit first. |
|
The methods a seed from |
The models a seed can read, for the page's picker: |
|
|
The model's raw output over annotation voxels |
|
The prediction as a probability, (channels, z, y, x), 0.5 at the model's decision boundary. |
|
Where the model says foreground: its |
|
The objects |
Fill the unannotated voxels of the box on screen from the model's prediction. |
|
Label every unannotated voxel of the box on screen background (1). |
|
Relabel the box on screen's foreground by connected component. |
|
Take back the last Seed, All Background or Split of the session's volume. |
Module Contents
- cellmap_flow.dashboard.routes.finetune.view_labels.logger
- cellmap_flow.dashboard.routes.finetune.view_labels.LARGE_BOX_VOXELS = 2097152
- cellmap_flow.dashboard.routes.finetune.view_labels.PREDICTION_TIMEOUT_SECONDS = 120
- cellmap_flow.dashboard.routes.finetune.view_labels.METADATA_TIMEOUT_SECONDS = 5
- cellmap_flow.dashboard.routes.finetune.view_labels.SEED_METHODS = ('components', 'mutex_watershed', 'distance_watershed', 'instances')
- cellmap_flow.dashboard.routes.finetune.view_labels.UNDO_DEPTH = 10
- cellmap_flow.dashboard.routes.finetune.view_labels.CELLPOSE_CELL_CHANNEL = 2
- cellmap_flow.dashboard.routes.finetune.view_labels.model_output(model_name)
(output_type, offsets): what the model is trained on, as submit decides it.autodetect_output_type: “affinities” (with the offsets, a JSON list) when the model’s script or channel names say so, “distance” for a distance model, a type’s declared target (“flows” for Cellpose), else “binary”. A model with no config here, or affinities without offsets, is “binary”: a threshold is all a seed can do with it.
- cellmap_flow.dashboard.routes.finetune.view_labels.methods_for(output_type, serves_integers)
The seed methods that fit a model’s output, the best fit first.
componentsfits every output (an instance label is foreground where it is not 0), so it is always offered, last unless nothing else fits.
- cellmap_flow.dashboard.routes.finetune.view_labels.UNANSWERED_RETRY_SECONDS = 60
- cellmap_flow.dashboard.routes.finetune.view_labels.seed_methods(model_name, host, base_model=None)
The methods a seed from
model_name’s server can use (methods_for).
- cellmap_flow.dashboard.routes.finetune.view_labels.seed_sources()
The models a seed can read, for the page’s picker:
models(every running server, oldest first),default, the one a seed reads when none is chosen (None when that is a choice for the user), andmethods, {model: the seed methods that fit its output, best first}; andbox_voxels, the volume’s output patch (z, y, x), the box a label action covers when it gives no other.
- cellmap_flow.dashboard.routes.finetune.view_labels.read_prediction(host, model_name, volume, lo, hi, info, postprocess=())
The model’s raw output over annotation voxels
[lo, hi).Read from its server as a layer is, with the dashboard’s input normalization and no postprocessing: the trainer’s target is set on the raw output, and that is where its decision boundary is. (
postprocessasks for one anyway: Cellpose’s masks of a flows server’s output, for a seed of its instances.) Each annotation voxel takes the served voxel its centre lies in, placed where neuroglancer draws the layer (prediction_voxel_override), so the seed lies under the prediction the user sees.Returns
(prediction, lo, hi): a (channels, z, y, x) array, float32 or, when the server serves integer labels, as served (an id past 2^24 is not exact in float32); and the box, shrunk to what the server covers.
- cellmap_flow.dashboard.routes.finetune.view_labels.probability(prediction, output_class=None, channels=None)
The prediction as a probability, (channels, z, y, x), 0.5 at the model’s decision boundary.
The boundary depends on the output’s activation: 0.5 on [0, 1] output (a sigmoid already applied; the cellmap distance models end in one, and 0.5 is their object boundary), 0 on tanh’s [-1, 1], and 0 on unbounded output, logits or a signed distance alike. Each is turned into a probability, so
channels– the affinity channels, say – can be averaged and one threshold means the same for every model.output_classis the server’s (serving.probe), or read off the values when it has none.
- cellmap_flow.dashboard.routes.finetune.view_labels.foreground_mask(prediction, output_class=None, channels=None, threshold=0.5)
Where the model says foreground: its
probability, averaged overchannels, overthreshold.thresholdis in probability whatever the activation: 0.5 is the model’s own boundary.
- cellmap_flow.dashboard.routes.finetune.view_labels.segment_prediction(method, prediction, output_class, channels, offsets, threshold=0.5, min_size=0, connectivity=1, per_slice=False)
The objects
methodmakes of the prediction: 0 background, 1..n (post.segment).thresholdis a probability (probability) for every method that thresholds: the foreground boundary for components and the distance watershed, and the mutex watershed’s bias, the affinity above which two voxels join.connectivityandper_sliceare the connected components’; the watersheds takeconnectivitytoo.instancessplits an id’s disconnected parts: a server numbers each chunk’s objects on its own (Cellpose’s from 1), and the box can span chunks.
- cellmap_flow.dashboard.routes.finetune.view_labels.seed_view_from_prediction()
Fill the unannotated voxels of the box on screen from the model’s prediction.
JSON body, all optional:
size_nm(as for mark-view),confirm(label a large box),select_channel(the channel the session trains, when it trains one),model(a name fromseed_sources; the latest finetune, else the base, when absent),method(one of the model’sseed_sourcesmethods; “components” when absent),threshold(probability, 0 to 1; the model’s own boundary, 0.5, when absent: seesegment_prediction),min_size(objects of fewer voxels are background),connectivity(1 faces, the default; 2 and edges; 3 all neighbours) andper_slice(components per z slice).
- cellmap_flow.dashboard.routes.finetune.view_labels.label_view_background()
Label every unannotated voxel of the box on screen background (1).
JSON body, all optional:
size_nmandconfirm, as for seed.
- cellmap_flow.dashboard.routes.finetune.view_labels.split_view_objects()
Relabel the box on screen’s foreground by connected component.
For a merge the model made: paint a background wall through the object, in every slice it spans, and click; the two sides get ids of their own (
fill.relabel_objects). A stroke joining two objects merges them. JSON body, all optional:size_nmandconfirm, as for seed;connectivityandper_slice, as for a seed’s components (withper_slice, a wall in one slice is enough, and each slice of an object gets an id of its own).
- cellmap_flow.dashboard.routes.finetune.view_labels.undo_view_labels()
Take back the last Seed, All Background or Split of the session’s volume.
The box goes back to what it held before, on the voxels still as that action left them: a stroke painted there since is kept. 409 when there is nothing to undo.