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 with keys ‘t1’ and/or ‘t2’ and values being the corresponding loaded and rescaled images. - 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.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.