HypVINN.run_prediction¶
- HypVINN.run_prediction.get_prediction(subject_name, modalities, orig_zoom, model, target_shape, view_opts, out_scale=None, mode='t1t2')[source]¶
Run the prediction for the Hypothalamus Segmentation model.
This function sets up the prediction process for the Hypothalamus Segmentation model. It runs the model for each plane (axial, coronal, sagittal), accumulates the prediction probabilities, and then generates the final prediction.
- Parameters:
- subject_name
str
The name of the subject.
- modalities
ModalityDict
A dictionary containing the modalities (T1 and/or T2) and their corresponding images.
- orig_zoom
npt.NDArray
[float
] The original zoom of the subject.
- model
Inference
The Inference object of the model.
- target_shape
tuple
[int
,int
,int
] The target shape of the output prediction.
- view_opts
ViewOperations
A dictionary containing the configurations for each plane.
- out_scale
optional
The output scale. Default is None.
- mode
ModalityMode
, default=”t1t2” The mode of operation. Can be ‘t1’, ‘t2’, or ‘t1t2’. Default is ‘t1t2’.
- subject_name
- Returns:
- pred_classes:
npt.NDArray
[int
] The final prediction of the model.
- pred_classes:
- HypVINN.run_prediction.load_volumes(mode, t1_path=None, t2_path=None)[source]¶
Load the volumes of T1 and T2 images.
This function loads the T1 and T2 images, checks their compatibility based on the mode, and returns the loaded volumes along with their affine transformations, headers, zoom levels, and sizes.
- Parameters:
- Returns:
tuple
A tuple containing the following elements: - modalities: A dictionary of
ndarrays
of rescaled images for keys ‘t1’ and/or ‘t2’. - affine: The affine transformation of the loaded image(s). - header: The header of the loaded image(s). - zoom: The zoom level of the loaded image(s). - size: The size of the loaded image(s).
- Raises:
RuntimeError
If the mode is inconsistent with the provided image paths, or if the number of dimensions of the data is invalid.
ValueError
If the mode is invalid, or if a header is missing.
AssertionError
If the mode is ‘t1t2’ but the T1 and T2 images have different resolutions or sizes.
- HypVINN.run_prediction.main(out_dir, t2, orig_name, sid, ckpt_ax, ckpt_cor, ckpt_sag, cfg_ax, cfg_cor, cfg_sag, hypo_segfile='hypothalamus.HypVINN.nii.gz', hypo_maskfile='hypothalamus_mask.HypVINN.nii.gz', qc_snapshots=False, reg_mode='coreg', threads=-1, batch_size=1, async_io=False, device='auto', viewagg_device='auto')[source]¶
Main function of the hypothalamus segmentation module.
- Parameters:
- out_dir
Path
The output directory where the results will be stored.
- t2
Path
,optional
The path to the T2 image to process.
- orig_name
Path
,optional
The path to the T1 image to process or FastSurfer orig image.
- sid
str
The subject ID.
- ckpt_ax
Path
The path to the axial checkpoint file.
- ckpt_cor
Path
The path to the coronal checkpoint file.
- ckpt_sag
Path
The path to the sagittal checkpoint file.
- cfg_ax
Path
The path to the axial configuration file.
- cfg_cor
Path
The path to the coronal configuration file.
- cfg_sag
Path
The path to the sagittal configuration file.
- hypo_segfile
str
, default=”hypothalamus.HypVINN.nii.gz” The name of the hypothalamus segmentation file. Default is hypothalamus.HypVINN.nii.gz.
- hypo_maskfile
str
, default=”hypothalamus_mask.HypVINN.nii.gz” The name of the hypothalamus mask file. Default is hypothalamus_mask.HypVINN.nii.gz.
- qc_snapshots
bool
,optional
Whether to create QC snapshots. Default is False.
- reg_mode“coreg”, “robust”, “none”, default=”coreg”
The registration mode to use. Default is “coreg”.
- threads
int
, default=-1 The number of threads to use. Default is -1, which uses all available threads.
- batch_size
int
, default=1 The batch size to use. Default is 1.
- async_io
bool
, default=False Whether to use asynchronous I/O. Default is False.
- device
str
, default=”auto” The device to use. Default is “auto”, which automatically selects the device.
- viewagg_device
str
, default=”auto” The view aggregation device to use. Default is “auto”, which automatically selects the device.
- out_dir
- Returns:
- HypVINN.run_prediction.option_parse()[source]¶
A function to create an ArgumentParser object and parse the command line arguments.
- Returns:
argparse.ArgumentParser
The parser object to parse arguments from the command line.
- HypVINN.run_prediction.prepare_checkpoints(ckpt_ax, ckpt_cor, ckpt_sag)[source]¶
Prepare the checkpoints for the Hypothalamus Segmentation model.
This function checks if the checkpoint files for the axial, coronal, and sagittal planes exist. If they do not exist, it downloads them from the default URLs specified in the configuration file.
- HypVINN.run_prediction.set_up_cfgs(cfg, out_dir, batch_size=1)[source]¶
Set up the configuration for the Hypothalamus Segmentation model.
This function loads the configuration, sets the output directory and batch size, and adjusts the output tensor dimensions based on the padded size specified in the configuration.