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_namestr

The name of the subject.

modalitiesModalityDict

A dictionary containing the modalities (T1 and/or T2) and their corresponding images.

orig_zoomnpt.NDArray[float]

The original zoom of the subject.

modelInference

The Inference object of the model.

target_shapetuple[int, int, int]

The target shape of the output prediction.

view_optsViewOperations

A dictionary containing the configurations for each plane.

out_scaleoptional

The output scale. Default is None.

modeModalityMode, default=”t1t2”

The mode of operation. Can be ‘t1’, ‘t2’, or ‘t1t2’. Default is ‘t1t2’.

Returns:
pred_classes: npt.NDArray[int]

The final prediction of the model.

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:
modeModalityMode

The mode of operation. Can be ‘t1’, ‘t2’, or ‘t1t2’.

t1_pathPath, optional

The path to the T1 image. Default is None.

t2_pathPath, optional

The path to the T2 image. Default is None.

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_dirPath

The output directory where the results will be stored.

t2Path, optional

The path to the T2 image to process.

orig_namePath, optional

The path to the T1 image to process or FastSurfer orig image.

sidstr

The subject ID.

ckpt_axPath

The path to the axial checkpoint file.

ckpt_corPath

The path to the coronal checkpoint file.

ckpt_sagPath

The path to the sagittal checkpoint file.

cfg_axPath

The path to the axial configuration file.

cfg_corPath

The path to the coronal configuration file.

cfg_sagPath

The path to the sagittal configuration file.

hypo_segfilestr, default=”hypothalamus.HypVINN.nii.gz”

The name of the hypothalamus segmentation file. Default is hypothalamus.HypVINN.nii.gz.

hypo_maskfilestr, default=”hypothalamus_mask.HypVINN.nii.gz”

The name of the hypothalamus mask file. Default is hypothalamus_mask.HypVINN.nii.gz.

qc_snapshotsbool, optional

Whether to create QC snapshots. Default is False.

reg_mode“coreg”, “robust”, “none”, default=”coreg”

The registration mode to use. Default is “coreg”.

threadsint, default=-1

The number of threads to use. Default is -1, which uses all available threads.

batch_sizeint, default=1

The batch size to use. Default is 1.

async_iobool, default=False

Whether to use asynchronous I/O. Default is False.

devicestr, default=”auto”

The device to use. Default is “auto”, which automatically selects the device.

viewagg_devicestr, default=”auto”

The view aggregation device to use. Default is “auto”, which automatically selects the device.

Returns:
int, str

0, if successful, an error message describing the cause for the failure otherwise.

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.optional_path(a)[source]

Convert a string to a Path object or None.

Parameters:
aPath, str

The input to convert.

Returns:
Path, None

The converted Path object.

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.

Parameters:
ckpt_axstr

The path to the axial checkpoint file.

ckpt_corstr

The path to the coronal checkpoint file.

ckpt_sagstr

The path to the sagittal checkpoint 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.

Parameters:
cfgyacs.config.CfgNode

The configuration node to load.

out_dirPath

The output directory where the results will be stored.

batch_sizeint, default=1

The batch size to use. Default is 1.

Returns:
yacs.config.CfgNode

The loaded and adjusted configuration node.