Skip to content

Add option to retain single channel for WNet3D in inference - #143

Merged
C-Achard merged 4 commits into
cy/helper-versionfrom
cy/wnet-channel
Nov 25, 2026
Merged

C-Achard merged 4 commits into
cy/helper-versionfrom
cy/wnet-channel

Conversation

@C-Achard

Copy link
Copy Markdown
Collaborator

Scope

Inference only, WNet3D only: an option to save, display and post-process a single output channel. Other models and training are unchanged.

Motivation

WNet3D outputs one channel per class. Inference saved and displayed every channel and ran instance segmentation on each, leaving users to identify and extract the foreground channel themselves.
Several utilities only support 2D or 3D inputs which made this missing post-processing step inconvenient.

Main changes

  • "Additional options" has a "Keep a single channel" checkbox, shown for WNet3D, with a "Channel" dropdown; the choice is passed to the worker as InferenceWorkerConfig.keep_channel (default None, all channels kept).
  • The worker selects the channel after the model output, before saving, display, artifact removal and instance segmentation.
  • CRF still receives all channels, since it needs every class probability; its result is reduced to the chosen channel before saving.
  • The dropdown lists one entry per class, read from custom .pth weights (length of encoder.out_b.module.8.bias); pretrained weights default to 2 classes with channel 1 selected (WNet_.default_channel).
  • The worker builds WNet3D with out_channels=model_info.num_classes; custom weights with 3 or more classes previously failed to load into the hard-coded 2-channel model.

Notes

  • The option is disabled for custom weights whose class count cannot be read: .onnx, .pt (TorchScript) and unreadable .pth files.
  • A channel that does not exist in the output, or an output without a channel axis (e.g. squeezed 1-class output), keeps the output unchanged and warns once per worker run.
  • Custom weights keep the selected channel when it still exists, else fall back to 0; unchecking custom weights resets to channel 1 which is the pretrained WNet3D default.

@C-Achard C-Achard added this to the v0.2.5 milestone Nov 25, 2026
@C-Achard C-Achard self-assigned this Nov 25, 2026
@C-Achard
C-Achard added this pull request to stack #138 November 25, 2026 12:40
- Disable channel choice for custom weights when number of classes is unknown (ONNX/pt)
- Adjust tooltips to clarify channel choice availability
@C-Achard C-Achard added the enhancement New feature or request label Nov 25, 2026
@C-Achard
C-Achard merged commit 7574eb6 into main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant