validate.seg.autoseg_pipeline#

Batch auto-segmentation pipeline. - Check install status, install missing AI models, then run+derive+export+log per patient.

Functions

checkModelsForStructures(structNames)

Resolve install status for the AI models structNames need.

installMissingModels(modelNums, installBaseDir)

Install each of modelNums via cerr.ai_models.install_utils, recording success in model_registry.

modelDevice(device)

The --device value for an AI model, from the settings' compute.device: "cuda" for gpu ("mps" on a Mac), "cpu" for cpu.

removePartialDownloads(modelNums, installBaseDir)

Delete weights downloads left unfinished (an aborted install) in the models' repositories: get_weights.py downloads into <repo>/weights/.get_weights_* and moves the weights into place only once they're complete.

runAIModel(modelNum, record, sessionDir[, ...])

Run one AI model on one patient (DICOM, NIfTI or NRRD).

validate.seg.autoseg_pipeline.checkModelsForStructures(structNames)[source]#

Resolve install status for the AI models structNames need.

Structures derived via a “classic” (non cerr.ai_models) method – structures.StructureDerivation.type == ‘classic’, aiModelNum None – need no install check; getRequiredAiModels still reports them (as aiModelNum None), so they’re filtered out here.

Returns:

(models, missingRecipe) –

models is {aiModelNum: {“name”: str, “installed”: bool}}

for the required AI models.

validate.seg.autoseg_pipeline.installMissingModels(modelNums, installBaseDir, progressCallback=None, force=False, shouldStop=None, **installOptions)[source]#

Install each of modelNums via cerr.ai_models.install_utils, recording success in model_registry.

Parameters:
  • modelNums (iterable[int]) – AI model numbers to ensure installed.

  • installBaseDir (str) – directory models are installed under (installed to installBaseDir/<modelName>).

  • progressCallback (callable) – optional f(message) status hook.

  • force (bool) – if True, re-install and replace the registry entry even for a modelNum already marked installed (e.g. its files were modified locally and need a fresh install). Default False skips anything already installed, as before. Also replaces the installed weights (install_utils forceWeights).

  • shouldStop (callable) – optional f() -> bool, checked before each model; True stops there (e.g. the install was aborted).

  • **installOptions – optional keyword arguments passed on to install_utils.main, e.g. weightsUrl, weightsFile, credentials, forceWeights, rebuildEnv, update. weightsUrl and weightsFile need a single model in modelNums.

Returns:

list of (modelNum, success, message) – message is the error text on failure, “” on success.

Raises:

ValueError – weightsUrl or weightsFile given with more than one model.

validate.seg.autoseg_pipeline.removePartialDownloads(modelNums, installBaseDir)[source]#

Delete weights downloads left unfinished (an aborted install) in the models’ repositories: get_weights.py downloads into <repo>/weights/.get_weights_* and moves the weights into place only once they’re complete.

Returns:

list[str] – the folders deleted.

validate.seg.autoseg_pipeline.modelDevice(device)[source]#

The –device value for an AI model, from the settings’ compute.device: “cuda” for gpu (“mps” on a Mac), “cpu” for cpu.

validate.seg.autoseg_pipeline.runAIModel(modelNum, record, sessionDir, progressCallback=None, outputDir=None, device=None)[source]#

Run one AI model on one patient (DICOM, NIfTI or NRRD).

Parameters:
  • modelNum (int) – AI model number.

  • record (validate.core.data_capsule.PatientRecord) – Patient info datastruct. For DICOM, scans are in record.file_info.data_dir. For NIfTI/NRRD, the scan is at record.file_info.scan_file; an NRRD scan is converted to NIfTI for the model.

  • sessionDir (str) – working folder for this run.

  • progressCallback (callable) – optional f(message) status hook.

  • outputDir (str or None) – folder the model writes its outputs to. Defaults to the patient’s folder, record.file_info.data_dir.

  • device (str or None) – the settings’ compute.device (“gpu” or “cpu”), passed as –device (see modelDevice) to models whose script accepts it. A model asked for a GPU it can’t use stops with an error, rather than running on the CPU. None leaves the choice to the model.