Enums & Config¶
Enumerations and the inference-configuration model used throughout SPINEPS.
spineps.seg_enums¶
spineps.seg_enums
¶
Enumerations describing image modalities, acquisitions, model types and pipeline phases used across SPINEPS.
MetaEnum
¶
Bases: EnumMeta
Enum metaclass enabling item in EnumClass membership tests by member name.
Source code in spineps/seg_enums.py
__contains__
¶
Return whether item names a member of the enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
Candidate member name to test for membership. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if |
Source code in spineps/seg_enums.py
Enum_Compare
¶
Bases: Enum
Base enum that compares equal to other enums by name/value and to plain strings by name.
Provides string-friendly equality, hashing and representation so members can be compared against and interchanged with their string names throughout the pipeline.
Source code in spineps/seg_enums.py
__eq__
¶
Compare this member against another enum or a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__value
|
object
|
Another enum member or a string holding a member name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the other enum matches by name and value, or the string matches this member's name. |
Source code in spineps/seg_enums.py
__str__
¶
Return the member as ClassName.MEMBER.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Human-readable identifier of the member. |
__repr__
¶
Return the same string as :meth:__str__.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Human-readable identifier of the member. |
__hash__
¶
Return the member's integer value as its hash.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The member's value, used for hashing. |
Modality
¶
Bases: Enum_Compare
Image modality of an input scan.
Members cover the MRI sequences and other image types SPINEPS can handle, e.g. T2-weighted (T2w), T1-weighted (T1w), Vibe/Dixon, CT, an existing segmentation (SEG), multi-planar reconstruction (MPR), proton density (PD) and FLAIR.
Source code in spineps/seg_enums.py
format_keys
classmethod
¶
Map modality members to the BIDS/file-name string keys that denote them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modalities
|
Self | list[Self]
|
A single modality member or a list of them. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: All file-name/format keys associated with the given modalities. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If a modality has no associated keys defined. |
Source code in spineps/seg_enums.py
Acquisition
¶
Bases: Enum_Compare
Acquisition plane of a scan.
Members denote the imaging plane: sag (sagittal), cor (coronal), ax (axial)
and iso (isotropic / no dominant plane).
Source code in spineps/seg_enums.py
format_keys
classmethod
¶
Map an acquisition member to the file-name string keys that denote it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acquisition
|
Self
|
The acquisition plane member. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: All file-name/format keys associated with the given acquisition. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the acquisition has no associated keys defined. |
Source code in spineps/seg_enums.py
SpinepsPhase
¶
Bases: Enum_Compare
Stage of the SPINEPS pipeline: semantic segmentation, vertebra instance segmentation or labeling.
Source code in spineps/seg_enums.py
ModelType
¶
Bases: Enum_Compare
Kind of model backing an inference config: an nnU-Net, a plain U-Net or a classifier.
Source code in spineps/seg_enums.py
InputType
¶
Bases: Enum_Compare
Type of input channel fed to a model.
img is the default image input and seg a segmentation input. The remaining members
are the Dixon/Vibe channels: in-phase (ip), out-of-phase (oop), water and fat.
Source code in spineps/seg_enums.py
OutputType
¶
Bases: Enum_Compare
Type of model output: a segmentation (seg), softmax logits or an uncertainty map (unc).
Source code in spineps/seg_enums.py
ErrCode
¶
Bases: Enum_Compare
Status/error codes returned by pipeline steps.
Indicates success (OK), that outputs already exist (ALL_DONE), a model/input compatibility
problem (COMPATIBILITY), an unknown failure (UNKNOWN), an empty mask or input (EMPTY)
or mismatched shapes (SHAPE).
Source code in spineps/seg_enums.py
spineps.utils.seg_modelconfig¶
spineps.utils.seg_modelconfig
¶
Inference configuration model: parses and holds the per-model settings stored in inference_config.json files.
Segmentation_Inference_Config
¶
Bucket for saving Inference Config data
Source code in spineps/utils/seg_modelconfig.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
__init__
¶
__init__(
logger: Logger_Interface | None,
log_name: str,
modality: str | tuple[str],
acquisition: str,
modeltype: str,
model_expected_orientation: AX_CODES,
available_folds: int | str | tuple[str] | tuple[int],
inference_augmentation: bool,
resolution_range: ZOOMS | tuple[ZOOMS, ZOOMS],
default_step_size: float,
labels: dict,
expected_inputs: list[InputType | str] = [
InputType.img
],
has_c1=False,
needs_corp=False,
sacrum_ids=DEFAULT_SACRUM_IDS,
cutout_size=DEFAULT_CUTOUT_SIZE,
corpus_size_cleaning=DEFAULT_CORPUS_SIZE_CLEANING,
corpus_border_threshold=DEFAULT_CORPUS_BORDER_THRESHOLD,
vert_size_threshold=DEFAULT_VERT_SIZE_THRESHOLD,
mapping=None,
**kwargs,
)
Build an inference config from raw (typically JSON-decoded) values.
String fields are resolved to the corresponding enum members and the label dictionaries are converted to integer label ids. Voxel-count cleaning thresholds are scaled by the resolution's voxel volume so they stay physically meaningful across resolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger_Interface | None
|
Logger for diagnostics; unknown extra kwargs are reported through it. |
required |
log_name
|
str
|
Name used as the logger prefix and to identify this config. |
required |
modality
|
str | tuple[str]
|
One or more modality names (see :class: |
required |
acquisition
|
str
|
Acquisition plane name (see :class: |
required |
modeltype
|
str
|
Model type name (see :class: |
required |
model_expected_orientation
|
AX_CODES
|
Axis-code orientation the model expects its input in. |
required |
available_folds
|
int | str | tuple[str] | tuple[int]
|
Folds available for inference/ensembling. |
required |
inference_augmentation
|
bool
|
Whether to apply test-time augmentation during inference. |
required |
resolution_range
|
ZOOMS | tuple[ZOOMS, ZOOMS]
|
Target voxel spacing, either a single zoom or a (min, max) range. |
required |
default_step_size
|
float
|
Default sliding-window step size used during inference. |
required |
labels
|
dict
|
Mapping of raw label keys to label names/ids resolved via |
required |
expected_inputs
|
list[InputType | str]
|
Input channels the model expects. Defaults to
|
[img]
|
has_c1
|
bool
|
Whether the model segments the C1 vertebra. Defaults to False. |
False
|
needs_corp
|
bool
|
Whether the model needs the vertebral corpus present. Defaults to False. |
False
|
sacrum_ids
|
tuple
|
Label ids treated as sacrum. Defaults to |
DEFAULT_SACRUM_IDS
|
cutout_size
|
tuple
|
Crop/cutout size in voxels. Defaults to |
DEFAULT_CUTOUT_SIZE
|
corpus_size_cleaning
|
int
|
Minimum corpus component size in voxels before resolution
scaling. Defaults to |
DEFAULT_CORPUS_SIZE_CLEANING
|
corpus_border_threshold
|
int
|
Border distance threshold for corpus cleaning. Defaults to
|
DEFAULT_CORPUS_BORDER_THRESHOLD
|
vert_size_threshold
|
int
|
Minimum vertebra size in voxels before resolution scaling.
Defaults to |
DEFAULT_VERT_SIZE_THRESHOLD
|
mapping
|
dict | None
|
Remapping of raw model label ids onto canonical ids. Defaults to a
copy of |
None
|
**kwargs
|
Ignored extra configuration keys, reported via |
{}
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If a label name in |
Source code in spineps/utils/seg_modelconfig.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
str_representation
¶
Render the config's attributes as a comma-separated 'key'=value string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
short
|
bool
|
If True, include only the modalities, acquisition and resolution range.
Defaults to False (all attributes except |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The formatted representation of the selected attributes. |
Source code in spineps/utils/seg_modelconfig.py
__str__
¶
Return the full string representation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
All attributes formatted via :meth: |
__repr__
¶
Return the short string representation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The key attributes formatted via :meth: |
load_inference_config
¶
load_inference_config(
json_dir: str | Path,
logger: Logger_Interface | None = None,
) -> Segmentation_Inference_Config
Load an inference configuration from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_dir
|
str | Path
|
Path to the |
required |
logger
|
Logger_Interface | None
|
Logger forwarded to the config for diagnostics. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Segmentation_Inference_Config |
Segmentation_Inference_Config
|
The config built from the file's contents. |