Getting Started
This section describes how to set-up the repository for inference only. For the development installation see the next section.
Environment Set-Up
Viseg is packaged on the Virdx Artifactory conda channel, to use it in your project you just have to add the virdx artifactory channel to your pyproject.toml under tool.pixi.projects as follows:
[tool.pixi.project]
channels = [
"https://quantco.jfrog.io/artifactory/api/conda/virdx",
"conda-forge",
]
You can then add the viseg package to your environment with:
pixi add viseg
Inference of Vicom images
To perform inference on individual vicom volumes you can use the VisegInferenceModel class. This can be either used with a ClearML model ID, or a local model path.
Anatomy Inference
from viseg.inference import VisegInferenceModel, binarize_mask
from vicom.utils.pytest_fixtures import create_synthetic_volume
t2_vol = create_synthetic_volume('T2', spacing = (1,1,3), image_size = (128, 128, 60))
# Anatomy Model by model_id
anatomy_model = VisegInferenceModel(model_id = '0033d77655c64fb4be60eb51d503649d')
# Alternatively, we could pass a local path
anatomy_model = VisegInferenceModel(model_path = '/path/to/local/model.pt')
# We pass the input as a list, with each input channel as an element, anatomy just takes the T2 image
anatomy_mask, probs, uncertainty = anatomy_model.predict_sample([t2_vol])
Lesion Inference
# Lesion Model
lesion_model = VisegInferenceModel(model_id = '6dbbdbd148f54c51a2b5acab4bedbb12')
# Create some dummy volumes (no adc option, hence using dwi but this is exemplary anyway)
# Lesion was trained with four input channels: T2, ADC, DWI (1400) and anatomy_mask
t2_vol = create_synthetic_volume('T2', spacing = (1,1,3), image_size = (128, 128, 60))
adc_vol = create_synthetic_volume('DWI', spacing = (2, 2, 3), image_size = (100, 100, 50))
dwi_vol = create_synthetic_volume('DWI', spacing = (2, 2, 3), image_size = (100, 100, 50))
# We need to provide a crop mask (= binary prostate mask)
prostate_mask = binarize_mask(anatomy_mask)
pred, probs, uncertainty = anatomy_model.predict_sample([t2_vol, adc_vol, dwi_vol, anatomy_mask], crop_mask = prostate_mask)
For more details on the parameter options for the VisegInferenceModel see the reference.