cellmap_flow.finetune.target_transforms
Target transforms for converting user annotations to training targets.
- Each transform takes a raw annotation tensor (B, 1, Z, Y, X) with values:
0 = unannotated (ignored in loss) 1 = background 2 = first foreground object 3 = second foreground object, etc.
- And produces:
target: (B, C, Z, Y, X) — training target matching model output channels mask: (B, C, Z, Y, X) or (B, 1, Z, Y, X) — valid loss mask
Classes
Base class for target transforms. |
|
Standard binary segmentation transform (current default behavior). |
|
Binary target broadcast to N channels. |
|
Compute affinity targets from instance labels. |
Module Contents
- class cellmap_flow.finetune.target_transforms.TargetTransform
Base class for target transforms.
- class cellmap_flow.finetune.target_transforms.BinaryTargetTransform
Standard binary segmentation transform (current default behavior).
Produces single-channel binary target: bg=0, fg=1. Mask marks annotated regions.
- class cellmap_flow.finetune.target_transforms.BroadcastBinaryTargetTransform(num_channels: int)
Binary target broadcast to N channels.
All output channels receive the same fg/bg target. Useful for treating multi-channel models (affinities, distances) as simple binary segmentation.
- num_channels
- class cellmap_flow.finetune.target_transforms.AffinityTargetTransform(offsets: List[List[int]], num_channels: int = None)
Compute affinity targets from instance labels.
- For each offset, affinity is:
1 if both voxels belong to the same foreground object (same label > 1) 0 if different objects, or either is background
The loss mask requires both voxels in each pair to be annotated (label > 0), producing a per-channel mask since each offset shifts differently.
- Parameters:
offsets – List of [dz, dy, dx] offset tuples defining neighbor relationships.
num_channels – Total number of model output channels. If greater than len(offsets), extra channels (e.g. LSDs) are masked out (mask=0) so they receive no gradient. If None, defaults to len(offsets).
- offsets
- num_channels