HypVINN.inference

class HypVINN.inference.Inference(cfg, threads=-1, async_io=False, device='auto', viewagg_device='auto')[source]

Class for running inference on a single subject.

Attributes

model

(torch.nn.Module) The model to use for inference.

model_name

(str) The name of the model.

Methods

setup_model(cfg)

Set up the model.

eval(val_loader, pred_prob, out_scale=None)[source]

Evaluate the model on a HypVINN dataset.

This method runs the model in evaluation mode on a HypVINN Dataset. It iterates over the given dataset and computes the model’s predictions.

Parameters:
val_loaderDataLoader

The DataLoader for the validation set.

pred_probtorch.Tensor

The tensor to update with the prediction probabilities.

out_scalefloat, optional

The scale factor for the output. Default is None.

Returns:
pred_prob: torch.Tensor

The updated prediction probabilities.

get_cfg()[source]

Get the configuration node.

This method returns the configuration node used in the Inference instance.

Returns:
yacs.config.CfgNode

The configuration node containing the parameters for the model.

get_device()[source]

Get the device.

This method returns the device and view aggregation device used in the Inference instance.

Returns:
tuple

The device and view aggregation device.

get_max_size()[source]

Get the maximum size of the output tensor.

Returns:
int or tuple

The maximum size. If the width and height of the output tensor are equal, it returns the width. Otherwise, it returns both the width and height.

get_model_height()[source]

Get the model height.

This method returns the height of the model defined in the model configuration.

Returns:
int

The height of the model.

get_model_width()[source]

Get the model width.

This method returns the width of the model defined in the model configuration.

Returns:
int

The width of the model.

get_modelname()[source]

Get the name of the model.

This method returns the name of the model used in the Inference instance.

Returns:
str

The name of the model.

get_num_classes()[source]

Get the number of classes.

This method returns the number of classes defined in the model configuration.

Returns:
int

The number of classes.

get_plane()[source]

Get the plane.

This method returns the plane defined in the data configuration.

Returns:
str

The plane.

load_checkpoint(ckpt)[source]

Load a model checkpoint.

This method loads a model checkpoint from a .pth file containing a state dictionary of a model.

Parameters:
ckptstr

The path to the checkpoint file. The checkpoint file should be a .pth file containing a state dictionary of a model.

run(subject_name, modalities, orig_zoom, pred_prob, out_res=None, mode='t1t2')[source]

Run the inference process on a single subject.

This method sets up the HypVINN DataLoader for the subject, runs the model in evaluation mode on the subject’s data, and returns the updated prediction probabilities.

Parameters:
subject_namestr

The name of the subject.

modalitiesModalityDict

The modalities of the subject.

orig_zoomnpt.NDArray[float]

The original zoom of the subject.

pred_probtorch.Tensor

The tensor to update with the prediction probabilities.

out_resfloat, optional

The resolution of the output. Default is None.

modeModalityMode, default=”t1t2”

The mode of the modalities. Default is ‘t1t2’.

Returns:
pred_prob: torch.Tensor

The updated prediction probabilities.

set_cfg(cfg)[source]

Set the configuration node.

Parameters:
cfgyacs.config.CfgNode

The configuration node containing the parameters for the model.

set_model(cfg=None)[source]

Set the model for the Inference instance.

Parameters:
cfgyacs.config.CfgNode, optional

The configuration node containing the parameters for the model. (Default = None).

setup_model(cfg=None)[source]

Set up the model.

This method sets up the model for inference.

Parameters:
cfgyacs.config.CfgNode, optional

The configuration node containing the parameters for the model.

Returns:
modeltorch.nn.Module

The model set up for inference.