Skip to content

Viseg segmentation inference

Run viseg anatomy/lesion inference using VisegInferenceModel, binarize_mask, and ClearML model registry (LATEST_ANATOMY_MODEL_ID). Points to vxData SDK for data access.

Current API (verified 2026-08-06)

from viseg.inference import VisegInferenceModel, binarize_mask
from viseg import LATEST_ANATOMY_MODEL_ID
import torch

# Load model from ClearML registry
model = VisegInferenceModel(
    model_id=LATEST_ANATOMY_MODEL_ID,  # "71aec22bf3044253b83a935b33141356" as of 2026-04-27
    device=torch.device("cuda:0"),
    n_test_flips=1,          # test-time augmentation (0=off, max 7)
    compute_entropy=True,
)

# Anatomy (1 channel: T2)
seg_vol, probs_vol, uncertainty_dict = model.predict_sample([t2_volume])

# Lesion (3+ channels: T2 + ADC + DWI, optionally + anatomy_mask)
seg_vol, probs_vol, uncertainty_dict = model.predict_sample(
    [t2_vol, adc_vol, dwi_vol],
    crop_mask=binary_prostate_mask,  # optional
)

Returns:

  • seg_volvicom.Volume, integer class labels [D, H, W]
  • probs_volvicom.Volume, softmax probabilities [N_classes, D, H, W]
  • uncertainty_dictdict[str, Volume]: "entropy" and/or "mutual_info" (mutual_info requires ensemble)

Segmentation labels (anatomy task)

0: background       5: pz (peripheral zone)
1: bladder_lumen    6: tz (transition zone)
2: bladder_wall     7: as (anterior stroma)
3: urethra          8: cz (central zone)
4: rectum           9: neurovascular_bundles
                   10: seminal_vesicles

Binary prostate mask

from viseg.inference import binarize_mask

binary = binarize_mask(
    seg_vol,
    foreground_classes=[5, 6, 7, 8],  # pz, tz, as, cz
    foreground_name="prostate",
    fill_incisions=True,
)

Model registry (ClearML)

Always use LATEST_ANATOMY_MODEL_ID from viseg/__init__.py rather than hardcoding an ID. The constant is updated automatically by the training pipeline.

Current value (2026-04-27): "71aec22bf3044253b83a935b33141356"

To query ClearML directly:

from clearml import Model

models = Model.query_models(
    project_name="viseg",
    tags=["production"],
    only_published=False,
    max_results=1,
)
latest_id = models[0].id

Or fetch by ID:

from clearml import InputModel
m = InputModel(model_id=LATEST_ANATOMY_MODEL_ID)
local_path = m.get_local_copy()

The ClearML server address and credentials come from your local ~/.clearml.conf — not from this page.

Data access

For pulling imaging volumes from the vxData platform, see mono/packages/vxdata-sdk/README.md. The legacy vxp_client package was part of the archived virdx/data-platform repo (archived 2026-05-27); data access APIs are now in the vxData SDK under mono/packages/vxdata-sdk.

What NOT to use

Do not import from viseg.study_inference — it has stale hardcoded model IDs and may fail with virdx_core version mismatches (InstanceConnection import error). Use viseg.inference directly.

Files to avoid:

  • viseg/study_inference/study_inference_params.py — outdated model IDs
  • viseg/study_inference/study_anatomy_inference.py — Study-based pipeline (stale)
  • viseg/study_inference/study_lesion_inference.py — Study-based pipeline (stale)

Vicom Volume I/O

from vicom import Volume
from vicom.nifti import load_volume_from_nifti, write_to_nifti
from vicom.processing import resample_volume

vol = load_volume_from_nifti("/path/to/file.nii.gz")
write_to_nifti(vol, path="output.nii.gz", add_timestamp=False, store_json=True)

# Resample to match another volume's grid
resampled = resample_volume(vol, ref=reference_vol)

Key Volume attributes: .data (numpy), .affine, .spacing, .volume_type, .b_value, .image_plane, .segmentation_labels

Pointers

  • viseg source: virdx/viseg/src/viseg/
  • Inference model: virdx/viseg/src/viseg/inference/inference_model.py
  • Utils (binarize_mask): virdx/viseg/src/viseg/inference/utils.py
  • Model constant: virdx/viseg/src/viseg/__init__.py
  • vxData SDK: mono/packages/vxdata-sdk/
Navigation

Type to search…

↑↓ navigate↵ selectEsc close