cellmap_flow.post.postprocessors
Attributes
Classes
Base class for post-processing methods. |
|
Apply sigmoid activation to convert logits to probabilities. |
|
Base class for post-processing methods. |
|
Base class for post-processing methods. |
|
One channel of label ids from a model's channels of scores: each |
|
Threshold, then fill the background holes each foreground blob encloses. |
|
An id per connected object of one channel's nonzero voxels ( |
|
Base class for post-processing methods. |
|
Objects from affinities by mutex watershed ( |
|
Base class for post-processing methods. |
|
Cellpose's masks, made from a Cellpose model's flows output. |
|
Base class for post-processing methods. |
|
Base class for post-processing methods. |
Functions
|
The dtype of ArgmaxPostprocessor's ids. |
|
The postprocessors' registry entries (input_normalize.op_listing), in LISTING_ORDER. |
|
Get postprocessors from either dict or list format. |
Module Contents
- cellmap_flow.post.postprocessors.logger
- class cellmap_flow.post.postprocessors.PostProcessor
Base class for post-processing methods.
- property is_segmentation
- problem_with(model_config, channels=None)
Why this step cannot run on
model_config’s output, or None when it can.Checked by the dashboard before it applies a chain: a step that fails on every chunk does so inside the model’s server, where the page shows only an empty layer.
channelsis how many channels reach the step when a step ahead of it sets the count (a ChannelSelection), else None: the model’s output, all of it.
- class cellmap_flow.post.postprocessors.SigmoidPostprocessor
Apply sigmoid activation to convert logits to probabilities.
- browser = True
- property dtype
- class cellmap_flow.post.postprocessors.DefaultPostprocessor(clip_min: float = -1.0, clip_max: float = 1.0, bias: float = 1.0, multiplier: float = 127.5)
Base class for post-processing methods.
- browser = True
- clip_min
- clip_max
- bias
- multiplier
- property dtype
- property is_segmentation
- class cellmap_flow.post.postprocessors.ThresholdPostprocessor(threshold: float = 0.5)
Base class for post-processing methods.
- browser = True
- threshold
- property dtype
- property is_segmentation
- cellmap_flow.post.postprocessors.argmax_dtype(channels, ids=None)
The dtype of ArgmaxPostprocessor’s ids.
With
ids, the smallest of uint8, uint16 and uint32 that holds the largest of them. Without, the ids are 1 tochannels: uint8 while every id, 0 tochannels, fits in it, else uint16.None, a count the caller does not know (a chain read without its model), is taken to fit uint8, which it does unless the model has over 255 channels.
- class cellmap_flow.post.postprocessors.ArgmaxPostprocessor(threshold: float | None = None, ids: str | list[int] | None = None)
One channel of label ids from a model’s channels of scores: each voxel’s id is the index of its highest-scoring channel, plus 1, or that channel’s id in
ids.For a model whose channels are classes that exclude each other (one softmax over them), or independent sigmoids that do not overlap; a ChannelSelection ahead of it chooses the channels that compete, and the ids count in its order. Id 0 is background: with
threshold, a voxel whose highest score is below it. Without one, every voxel is its best channel’s. A tie goes to the lowest channel, as numpy’s argmax gives it. A NaN never wins, ranking below every number, -inf too, and a voxel that is NaN in every channel is background, threshold or not. Each voxel’s id is its own, so a chunk needs nothing from its neighbours.idsgives each channel it is given, in order, the id its voxels get (a model’s classes as a dataset numbers them: “50,51,37”); an id of 0 makes that channel background too. There must be one per channel. The ids are uint8 for up to 255 channels, else uint16, or withidsthe smallest of uint8, uint16 and uint32 that holds them (argmax_dtype).- browser = True
- threshold = None
- ids = None
- problem_with(model_config, channels=None)
With
ids, a count of them that is not that of the channels reaching it, when that is known: set by a step ahead of it, else the model’s output channels as its running server or the geometry cache knows them (geometry_cache.known_geometry; the model is not built).
- output_info(dtype, channels)
(dtype, channels, is_segmentation)of what this step returns.dtypeandchannelsdescribe what it is given. By default the step’s declareddtypereplaces the incoming one (Nonekeeps it), anum_channelsattribute (only steps that change the count have one) replaces the channel count, andis_segmentationis the step’s own, whereNonemeans it does not say. A step whose output depends on its input in some other way overrides this.
- class cellmap_flow.post.postprocessors.FillHolesPostprocessor(threshold: float = 0.0)
Threshold, then fill the background holes each foreground blob encloses.
For compact single-instance organelles (a nucleus, say) that never have interior gaps; not for structures with a real lumen. It runs per chunk with no halo, so a hole that touches the chunk’s boundary is not enclosed within the chunk and stays unfilled.
- threshold
- property dtype
- property is_segmentation
- class cellmap_flow.post.postprocessors.LabelPostprocessor(channel: int = 0, connectivity: int = 1, min_size: int = 0, per_slice: bool = False)
An id per connected object of one channel’s nonzero voxels (
segment.connected_components).connectivity: 1 faces (the default), 2 faces and edges, 3 all neighbours.min_size: objects of fewer voxels become background.per_slice: each z slice labelled on its own, in 2D. The other channels pass through, as uint32.- browser = True
- channel = 0
- connectivity
- min_size = 0
- per_slice
- property dtype
- property is_segmentation
- class cellmap_flow.post.postprocessors.MortonSegmentationRelabeling(channel: int = 0)
Base class for post-processing methods.
- browser = True
- channel = 0
- num_previous_segments = 0
- use_exact = True
- property dtype
- property is_segmentation
- class cellmap_flow.post.postprocessors.AffinityPostprocessor(bias: float = 0.5, neighborhood: str = '[\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n [3, 0, 0],\n [0, 3, 0],\n [0, 0, 3],\n [9, 0, 0],\n [0, 9, 0],\n [0, 0, 9],\n ]')
Objects from affinities by mutex watershed (
segment.mutex_watershed).bias: the affinity above which neighbours join, and below which a fragment’s mean makes it background; 0.5 by default, the midpoint of the probabilities a sigmoid gives (with 0 every edge joined and one object came out).neighborhood: the offset each channel compares, as the model was trained with. Ids are offset by the chunk’s Morton index, so they are unique across chunks.- browser = True
- bias
- neighborhood
- use_exact = True
- num_previous_segments = 0
- property dtype
- property is_segmentation
- property num_channels
- class cellmap_flow.post.postprocessors.SimpleBlockwiseMerger(channel: int = 0, face_erosion_iterations: int = 0)
Base class for post-processing methods.
- browser = True
- channel = 0
- face_erosion_iterations = 0
- use_exact = True
- equivalences
- chunk_slice_position_to_coords_id_dict
- slices
- keys_to_skip
- equivalences_json()
The equivalences so far, read while no other chunk is adding to them.
- calculate_equivalences()
- property dtype
- property is_segmentation
- class cellmap_flow.post.postprocessors.CellposeMasksPostprocessor(flow_threshold: float = 0.4, cellprob_threshold: float = 0.0, min_size: int = 15, stitch_threshold: float = 0.0, niter: int = 200)
Cellpose’s masks, made from a Cellpose model’s flows output.
Cellpose turns its three output channels into objects by following each pixel’s flow to where the flows converge. Run here, on a server with
output: flows(channels flow_y, flow_x and cell, the probability), its thresholds can be changed from the dashboard and the layer redrawn, whereoutput: masksfixes them when the server starts. Put it first in the chain, on the flows as served. It needs Cellpose, which a Cellpose model’s server has.From a 2D model’s flows each slice is segmented on its own, as Cellpose segments a 2D image;
stitch_thresholdabove 0 joins a slice’s object to the next slice’s one it overlaps by that IoU (Cellpose’s stitch3D), else each slice’s ids follow the previous slice’s. From a 3D model’s (do_3d: flow_z, flow_y, flow_x and cell) the chunk is segmented in 3D, following the 3D flows, as Cellpose’s do_3D does;flow_thresholdandstitch_thresholdmean nothing there. Ids are unique within the chunk: follow with MortonSegmentationRelabeling for ids unique across chunks.- Parameters:
flow_threshold – how far an object’s flows may be from those its shape implies before it is dropped (Cellpose’s; 0 keeps all).
cellprob_threshold – the cell probability, as a logit, over which a pixel is followed (Cellpose’s; 0 is a probability of 0.5).
min_size – objects of fewer voxels are removed (per slice; after stitching when stitched; in 3D, per 3D object).
stitch_threshold – IoU joining objects across slices; 0 is off.
niter – flow-following steps (Cellpose’s default, 200).
- uses_device = True
- flow_threshold
- cellprob_threshold
- min_size = 15
- stitch_threshold
- niter = 200
- problem_with(model_config, channels=None)
None for a Cellpose model (or a finetune of one) served with
output: flows.
- property dtype
- property is_segmentation
- property num_channels
- class cellmap_flow.post.postprocessors.ChannelSelection(channels: str = '0')
Base class for post-processing methods.
- browser = True
- channels
- property num_channels
- class cellmap_flow.post.postprocessors.LambdaPostprocessor(expression: str)
Base class for post-processing methods.
- browser = True
- expression
- property dtype
- cellmap_flow.post.postprocessors.LISTING_ORDER = ['SigmoidPostprocessor', 'DefaultPostprocessor', 'ThresholdPostprocessor', 'ChannelSelection',...
- cellmap_flow.post.postprocessors.get_postprocessors_list() list[dict]
The postprocessors’ registry entries (input_normalize.op_listing), in LISTING_ORDER.
- cellmap_flow.post.postprocessors.get_postprocessors(elms) list[PostProcessor]
Get postprocessors from either dict or list format.